Replies: 2 comments 1 reply
-
Noticing this, as well. // This works
import api from 'some-cjs-api'
api.default('foo') // This fails
import api from 'some-cjs-api'
api('foo') What the file looks like: import { c as createCommonjsModule } from '../common/_commonjsHelpers-38687f85.js';
var foo = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, '__esModule', { value: true });
.... some code ...
exports.foo = foo;
exports.default = foo;
});
export default foo; |
Beta Was this translation helpful? Give feedback.
-
Unfortunately this behavior currently lives in Rollup’s CommonJS plugin which Snowpack uses under-the-hood. We’d like for there to be a solution to this, but unfortunately the problem is complicated, and multi-faceted. Ideally this is solved in Rollup, because once it’s solved there, it’ll be solved for a huge portion of the JS community. We also know that these errors are new for people, because in a webpack (etc.) world, your ESM code is actually being downconverted to CJS. You’re not seeing export errors because much ESM is being stripped away, as well as CJS being a little more mature as an ecosystem. Snowpack is different in that it keeps your ESM code and tries to upconvert all the CJS packages it can to ESM. So it brings with it a few different errors/problems than people are used to. We do encourage using ESM packages whenever possible, but I know that isn’t realistic in every case. Until then, simply try and use the imports that work best for you. And sometimes that involves using the |
Beta Was this translation helpful? Give feedback.
-
snowpack@2.7.5
I want to use @alifd/next in the snowpack project. But when i run
snowpack dev
, this error occured:Uncaught TypeError: inherits is not a function next.js:3780
And the 'inherits' was defined like this:
I found 'inherits.default' is the right function. And this issue seems like rollup#469
What should i do to resolve this problem?
Beta Was this translation helpful? Give feedback.
All reactions