You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
require not supported after upgrading to axios 1.1.2 #5091
we are getting below error after upgrading axios to the 1.1.2 version
2022-10-11T04:56:57.575682812Z stderr F Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /app/node_modules/axios/package.json.
| | 2022-10-11T04:56:57.575671912Z stderr F require() of /app/node_modules/axios/index.js from /app/server.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
| | 2022-10-11T04:56:57.575663912Z stderr F require() of ES modules is not supported.
| | 2022-10-11T04:56:57.575654512Z stderr F Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /app/node_modules/axios/index.js
| | 2022-10-11T04:56:57.575647612Z stderr F
| | 2022-10-11T04:56:57.575640211Z stderr F ^
| | 2022-10-11T04:56:57.575628111Z stderr F throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
| | 2022-10-11T04:56:57.575556611Z stderr F internal/modules/cjs/loader.js:1172
Hello 👋 a similar issue happens to me on a simple Nuxt 2 project.
Must use import to load ES Module: /sandbox/node_modules/axios/index.js require() of ES modules is not supported. require() of /sandbox/node_modules/axios/index.js from /sandbox/node_modules/vue-server-renderer/build.dev.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /sandbox/node_modules/axios/package.json.
@amercier Did you find a temporary workaround to this problem? I'm getting the same issue today when trying to run npm run generate in my Nuxt 2 project.
When I try and run the module using node -r esm index.js I get this error:
Error [ERR_REQUIRE_ESM]: require() of ES Module .../test-axios/node_modules/axios/index.js not supported.
Instead change the require of index.js in null to a dynamic import() which is available in all CommonJS modules.
When I try and run the module using node -r esm index.js I get this error:
Error [ERR_REQUIRE_ESM]: require() of ES Module .../test-axios/node_modules/axios/index.js not supported.
Instead change the require of index.js in null to a dynamic import() which is available in all CommonJS modules.
Hello, I met the same problem. Still a bit confused to me: How to resolve this problem? By "It has fixed using require", You mean just replacing the import by require in the source code when using axios?
Hi, I too faced the similar issue even in latest v1.6.8,
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/Github/test-axios/node_modules/axios/index.js not supported.
Instead change the require of index.js in null to a dynamic import() which is available in all CommonJS modules.
I was using esm so switching to esm-wallaby fixed my problems.
Reacted by Santiago Petrone, Zifeng Liang and Khoa Nguyen
Activity
everlectric-technology commentedon Oct 16, 2022
We have the same issue.
jasonsaayman commentedon Oct 17, 2022
Can you please send a snippet of the import in app/server.js
amercier commentedon Oct 18, 2022
Hello 👋 a similar issue happens to me on a simple Nuxt 2 project.
"axios": "^1.1.3"as dependencyaxiosfrom anywhereCould be related: #5150
sts-ryan-holton commentedon Oct 22, 2022
@amercier Did you find a temporary workaround to this problem? I'm getting the same issue today when trying to run
npm run generatein my Nuxt 2 project.yanheng888 commentedon Oct 23, 2022
I solve this problem by using the command: npm i [email protected]
I think this problem is because the latest axios does not support require()
amercier commentedon Oct 25, 2022
@sts-ryan-holton: No, no workaround for version 1.x so far I'm afraid.
@yanheng888: Yes, also I can confirm
0.27.2works great as well, I'd recommend using the latest0.xuntil this is fixed.AlexBosio95 commentedon Oct 29, 2022
Thanks !
lucas55i commentedon Dec 23, 2022
@amercier Thank you very much, it helped me a lot!
sabaesm1377 commentedon Jan 1, 2023
thanks.it was helpful for me to,but i want know the reason?
and how it can be fixed?
itanglo commentedon Jan 18, 2023
Thanks @DigitalBrainJS @jasonsaayman
It has fixed using
require.The problem I'm having is that my project uses the github.com/standard-things/esm package.
When I try and run the module using
node -r esm index.jsI get this error:Using:
The index.js file only contains:
I have asked a question here too: https://stackoverflow.com/questions/75152442/error-err-require-esm-require-of-es-module-when-using-esm-package-with-ax
alintongutierrez2007 commentedon Feb 2, 2023
i fixed this error, only change axios version in Package.json in my proyect: i had : 1.3.1 y change to 0.24.0, and run "npm i " again and work it
xeoshow commentedon Feb 9, 2023
Hello, I met the same problem. Still a bit confused to me: How to resolve this problem? By "It has fixed using
require", You mean just replacing the import by require in the source code when using axios?Thanks a lot.
Best regards, Jason
mohdWajid19 commentedon Mar 22, 2024
Hi, I too faced the similar issue even in latest v1.6.8,
I was using
esmso switching toesm-wallabyfixed my problems.