Skip to content

.mjs fails webpack build #493

@peterbakonyi05

Description

@peterbakonyi05

When using node-fetch with webpack v4.8.3, bundling fails with node-fetch v2.2. By default webpack will resolve the module entry from package.json. Webpack supports .mjs extension, it seems the problem is the ES6 imports from the built-in node_modules like http, which are being shipped in CommonJS format.

Is there a plan to support webpack 4 with the new .mjs format?

As a temporary workaround the issue can be solved by changing the mainFields entry to mainFields: ["main", "module"]. Note: this will affect all modules.

Error:

ERROR in ./node_modules/node-fetch/lib/index.mjs
1049:34-46 Can't import the named export 'STATUS_CODES' from non EcmaScript module (only default export is available)
 @ ./node_modules/node-fetch/lib/index.mjs
 @ ./apps/server/src/test.js

ERROR in ./node_modules/node-fetch/lib/index.mjs
1142:16-21 Can't import the named export 'parse' from non EcmaScript module (only default export is available)
 @ ./node_modules/node-fetch/lib/index.mjs
 @ ./apps/server/src/test.js

ERROR in ./node_modules/node-fetch/lib/index.mjs
1145:16-21 Can't import the named export 'parse' from non EcmaScript module (only default export is available)
 @ ./node_modules/node-fetch/lib/index.mjs
 @ ./apps/server/src/test.js

ERROR in ./node_modules/node-fetch/lib/index.mjs
1149:15-20 Can't import the named export 'parse' from non EcmaScript module (only default export is available)
 @ ./node_modules/node-fetch/lib/index.mjs
 @ ./apps/server/src/test.js

ERROR in ./node_modules/node-fetch/lib/index.mjs
1194:9-15 Can't import the named export 'format' from non EcmaScript module (only default export is available)
 @ ./node_modules/node-fetch/lib/index.mjs
 @ ./apps/server/src/test.js

ERROR in ./node_modules/node-fetch/lib/index.mjs
1352:51-58 Can't import the named export 'resolve' from non EcmaScript module (only default export is available)
 @ ./node_modules/node-fetch/lib/index.mjs
 @ ./apps/server/src/test.js

ERROR in ./node_modules/node-fetch/lib/index.mjs
1413:27-38 Can't import the named export 'PassThrough' from non EcmaScript module (only default export is available)
 @ ./node_modules/node-fetch/lib/index.mjs
 @ ./apps/server/src/test.js

ERROR in ./node_modules/node-fetch/lib/index.mjs
1460:29-40 Can't import the named export 'PassThrough' from non EcmaScript module (only default export is available)
 @ ./node_modules/node-fetch/lib/index.mjs
 @ ./apps/server/src/test.js

ERROR in ./node_modules/node-fetch/lib/index.mjs
496:11-22 Can't import the named export 'PassThrough' from non EcmaScript module (only default export is available)
 @ ./node_modules/node-fetch/lib/index.mjs
 @ ./apps/server/src/test.js

ERROR in ./node_modules/node-fetch/lib/index.mjs
497:11-22 Can't import the named export 'PassThrough' from non EcmaScript module (only default export is available)
 @ ./node_modules/node-fetch/lib/index.mjs
 @ ./apps/server/src/test.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions