standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.26k stars 146 forks source link

Incorrect "main" entry in package.json is used #770

Closed dorian-marchal closed 5 years ago

dorian-marchal commented 5 years ago

When a package with a faulty main entry is imported, esm throws with:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined

Without using esm, index.js is used as the entry point.

Note that this is a regression in 3.2.21. 3.2.20 works as expected.

Here is a small repro using find-parent-dir (a package with a bad main entry): https://github.com/dorian-marchal/esm-issue

$ git clone https://github.com/dorian-marchal/esm-issue
Cloning into 'esm-issue'...

$ cd esm-issue/

$ node -v
v10.14.1

$ npm ls esm
esm-issue@1.0.0 /tmp/esm-issue
└── esm@3.2.21

$ node without-esm.js
OK

$ node with-esm.js
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at assertPath (path.js:39:11)
    at dirname (path.js:1268:5)
    at Object.<anonymous> (/tmp/esm-issue/with-esm.js:2:1)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)

$ npm install esm@3.2.20

$ node with-esm.js
OK
jdalton commented 5 years ago

Thank you @dorian-marchal!

This is hitting because esm has early adopted a change coming in Node (soon). This is good to know so I can pass this along to them.

Update:

Turns out it was typos on my end.

Update:

esm v3.2.21 is released :tada:

dorian-marchal commented 5 years ago

Thank you! :muscle:

dorian-marchal commented 5 years ago

I think you meant 3.2.22* (the latest version on npm).

Screenshot_20190329-084114

GitHub releases don't seem to match npm ones (unless you amended 3.2.21 on npm, this issue was fixed in 3.2.22).