Getting ERR_MODULE_NOT_FOUND when trying to use readme code sample
AleksandrHovhannisyan opened this issue · 1 comments
I'm unable to use the module; this may be user error, but I also tried writing tests for the package and ran into a similar error where both ava and jest were unable to find @bramus/range
unless I changed the import to @bramus/range/dist/index.js
.
I think it may have something to do with the fact that the packages don't have a root index.js
and instead export a dist
folder.
Steps to repro
- Create a blank package:
npm init
oryarn init
. - Step
type: "module"
inpackage.json
. - Install the package per the README:
yarn add @bramus/pagination-sequence
. - Create an
index.js
with the following contents:
import { generate } from '@bramus/pagination-sequence';
const sequence = generate(67, 74);
Run node index.js
. Observe the following error:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '/sandbox/node_modules/@bramus/pagination-sequence/' imported from /sandbox/index.js
Changing the import statement to @bramus/pagination-sequence/dist/index.js
works.
Environment
Node version: 16.13.0
I was under the impression that node would properly check the "module"
value from package.json
, but apparently that's not the case: it always calls legacyMainResolve
internally.
Added a "main"
key to fix this error, but that will most likely conflict with legacy CommonJS imports (which are not supported).