Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot load macro with .cjs extension in package with type: module #11555

Open
sergeysova opened this issue Oct 15, 2021 · 2 comments
Open

Cannot load macro with .cjs extension in package with type: module #11555

sergeysova opened this issue Oct 15, 2021 · 2 comments

Comments

@sergeysova
Copy link

sergeysova commented Oct 15, 2021

I made a package with a macro.cjs file, that added to package.json:exports, please note package.json has type: module.

Describe the bug

I got an error:

Cannot find module '@effector/patronum/macro' from '/home/runner/work/patronum/patronum/integration/cra/src'

    Require stack:
      src/App.js
      src/App.test.js


    However, Jest was able to find:
    	'./demo.test.ts'
    	'./demo.ts'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'].

I checked up babel-plugin-macros has support for .cjs macros: https://github.com/kentcdodds/babel-plugin-macros/blob/master/src/index.js#L5

Did you try recovering your dependencies?

Yep

Which terms did you search for in User Guide?

Environment

Environment Info:

  current version of create-react-app: 4.0.3
  running from /Users/sova/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app

  System:
    OS: macOS 11.5.2
    CPU: (8) arm64 Apple M1
  Binaries:
    Node: 16.5.0 - ~/.nvm/versions/node/v16.5.0/bin/node
    Yarn: 1.22.11 - ~/.nvm/versions/node/v16.5.0/bin/yarn
    npm: 7.19.1 - ~/.nvm/versions/node/v16.5.0/bin/npm
  Browsers:
    Chrome: 94.0.4606.81
    Edge: Not Found
    Firefox: 90.0.2
    Safari: 14.1.2
  npmPackages:
    react: ^17.0.1 => 17.0.2
    react-dom: ^17.0.1 => 17.0.2
    react-scripts: ^4.0.3 => 4.0.3
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

Also, I made an integration test for CRA:

  1. I publish the package to the GitHub registry
  2. Installed it to the app based on CRA
  3. Ran tests on file

Expected behavior

CRA should load macro with .cjs extension from another package.

Actual behavior

image

Reproducible demo

https://github.com/effector/patronum/tree/main/integration/cra/src

https://github.com/effector/patronum/runs/3848203844


I can't change .cjs to .js in type:module, because module system will think it is ESModule in .js file.

image

But CRA doesn't allow me to import macro.cjs

@stale
Copy link

stale bot commented Jan 9, 2022

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Jan 9, 2022
@fryorcraken
Copy link

I am guessing this is resolved by #12605 which ensure babel process .cjs file in dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants