Closed tstibbs closed 3 years ago
Thank you for reaching out, @tstibbs. I'm a bit surprised by the problem you're running into, for two reasons.
Theoretical reason: the Node.js documentation states that
When importing CommonJS modules, the
module.exports
object is provided as the default export. Named exports may be available, provided by static analysis as a convenience for better ecosystem compatibility.
I ensured that this static analysis was possible in the underscore-node-f.cjs
by listing each named export separately with the exports.name = ...
syntax. The error message you're getting from Node 14.8.0 seems like Node.js is contradicting its own documentation.
Empirical reason: I made a CI test that is very similar to yours and which passes without a problem in Node 14.
Of course, I don't doubt your report and of course, I want this to work. Before I invest a lot of effort again into supporting Node.js's exotic "support" for ESM, though: would you mind trying whether upgrading to Node.js 14.17 solves the problem for you?
Yes, a node upgrade fixed it... (14.13.0 was the latest available in my package repo but that seemed to be enough). Looking at the changelog it looks like the CJS export detection didn't appear until 14.13 (https://github.com/nodejs/node/pull/35249).
I probably should have tried that first, thanks for the pointer and the well reasoned response, and sorry for the spurious report!
No problem @tstibbs, I'm glad your problem has been solved!
When importing underscore into an ES6 module, an error is raised by the compiler.
To reproduce
Populate
index.mjs
like this:npm install underscore@1.13.1
node index.mjs
An error will be logged as follows:
What I've tried
.js
file and declaring"type": "module"
in thepackage.json
results in the same error.import {some} from 'underscore'
) results in the same error.Workaround
1.12.1
with the 'default' import styleEnvironment
Node version: 14.8.0 npm version: 7.10.0