question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't import the named export 'deferred' from non EcmaScript module (only default export is available)

See original GitHub issue

Describe the bug

I am trying to use it in AWS Lambda. The tool chain I am using is serverless and serverless-webpack plugin. Webpack complains about “Can’t import … from non EcmaScript module” in Node 14 environment:

[2022-05-18T10:10:53.414Z] ERROR in ./node_modules/axios-cache-interceptor/dist/index.mjs 1:1278-1288

[2022-05-18T10:10:53.414Z] Can't import the named export 'deferred' from non EcmaScript module (only default export is available)

[2022-05-18T10:10:53.414Z]  @ ./api.ts

[2022-05-18T10:10:53.414Z]  @ ./handler.ts

[2022-05-18T10:10:53.414Z] 

[2022-05-18T10:10:53.414Z] ERROR in ./node_modules/axios-cache-interceptor/dist/index.mjs 1:6483-6489

[2022-05-18T10:10:53.414Z] Can't import the named export 'hash' from non EcmaScript module (only default export is available)

[2022-05-18T10:10:53.414Z]  @ ./api.ts

[2022-05-18T10:10:53.414Z]  @ ./handler.ts

[2022-05-18T10:10:53.414Z] 

[2022-05-18T10:10:53.414Z] ERROR in ./node_modules/axios-cache-interceptor/dist/index.mjs 1:485-492

[2022-05-18T10:10:53.414Z] Can't import the named export 'parse' from non EcmaScript module (only default export is available)

[2022-05-18T10:10:53.414Z]  @ ./api.ts

[2022-05-18T10:10:53.414Z]  @ ./handler.ts

[2022-05-18T10:10:53.414Z]  

[2022-05-18T10:10:53.414Z]  Error ---------------------------------------------------

[2022-05-18T10:10:53.414Z]  

[2022-05-18T10:10:53.414Z]   Error: Webpack compilation error, see stats above

[2022-05-18T10:10:53.414Z]       at /home/ec2-user/workspace/services_feature_cache-term-info/statement/stmt-results/node_modules/serverless-webpack/lib/compile.js:37:15

[2022-05-18T10:10:53.414Z]       at arrayEach (/home/ec2-user/workspace/services_feature_cache-term-info/statement/stmt-results/node_modules/serverless-webpack/node_modules/lodash/lodash.js:530:11)

[2022-05-18T10:10:53.414Z]       at Function.forEach (/home/ec2-user/workspace/services_feature_cache-term-info/statement/stmt-results/node_modules/serverless-webpack/node_modules/lodash/lodash.js:9410:14)

[2022-05-18T10:10:53.414Z]       at /home/ec2-user/workspace/services_feature_cache-term-info/statement/stmt-results/node_modules/serverless-webpack/lib/compile.js:34:7

[2022-05-18T10:10:53.414Z]       at tryCatcher (/home/ec2-user/workspace/services_feature_cache-term-info/statement/stmt-results/node_modules/bluebird/js/release/util.js:16:23)

BTW, in tsconfig.json, “target” and “module” decide the compatibility level of your npm package. If you specify ESNext, that means your package can only be guaranteed to work in the environment that supports all features of ESNext. I usually set that to ES2017 so that my package can work in Node 10+.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
james-hucommented, May 18, 2022

Found a workaround:

config.module.rules.push({
  test: /\.mjs$/,
  include: /node_modules/,
  type: "javascript/auto",
});
0reactions
arthurfiorettecommented, May 18, 2022

Thanks, this means a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't import the named export XXXX from non EcmaScript ...
the solution is to make sure that you have a webpack.config.js file in the root of your project directory that looks something like...
Read more >
Can't import the named export 'Button' from non EcmaScript ...
Can't import the named export 'BaseMessageSignerWalletAdapter' from non EcmaScript module (only default export is available) #268.
Read more >
Can't import the named export from non EcmaScript module
Hi My site name is stupefied-lamarr-20c8d9 On the server side of my app I have lambda functions and within those I'm using apollo-server-lambda...
Read more >
"Can't import the named export from non EcmaScript module ...
KJS: "Can't import the named export from non EcmaScript module (only default export is available)" with react-map-gl-draw external interface. Relates to 1.
Read more >
can't import the named export from non ecmascript module ...
This means your bundler resolves .mjs files, however it doesn't know that they are ESM modules. On webpack, you can add the following...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found