-
Notifications
You must be signed in to change notification settings - Fork 667
Description
Do you want to request a feature or report a bug?
bug
What is the current behavior?
If you have require('./index.cjs')
you will have issue:
Error: While trying to resolve module `lib` from file `project/index.js`, the package `project/node_modules/lib/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`project/node_modules/lib/index.cjs`. Indeed, none of these files exist:
* project/node_modules/lib/index.cjs(.native|.web.js|.native.js|.js|.web.json|.native.json|.json|.web.ts|.native.ts|.ts|.web.tsx|.native.tsx|.tsx)
* project/node_modules/lib/index.cjs/index(.native|.web.js|.native.js|.js|.web.json|.native.json|.json|.web.ts|.native.ts|.ts|.web.tsx|.native.tsx|.tsx)
If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install
and yarn test
.
- Create empty project
- Add
lib.cjs
- Create
index.js
withrequire('./lib.cjs')
What is the expected behavior?
Load .cjs
files as any .js
files.
Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.
- No Metro config
- Metro 0.59.0
- Node 13.11.0
- Yarn 1.22.4
Extra details
I opened this issue because users of my dual CJS/ESM project have a problem with using my lib to React Native
ai/nanoevents#44 (comment)
You had .mjs
issue before, but it was closed because in 2017 it was not clear about .mjs
standard. Now .mjs
and .cjs
is an official Node.js API.