anthonygauthier / axios-curlirize

axios plugin converting requests to cURL commands, saving and logging them.
MIT License
186 stars 31 forks source link

Node 14, AC 2.0.0: error: Must use import to load ES Module #57

Closed jcollum-nutrien closed 2 years ago

jcollum-nutrien commented 2 years ago
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/justin.collum2@nutrien.com/work/seed-association-service/node_modules/axios-curlirize/src/main.js
require() of ES modules is not supported.
require() of /Users/justin.collum2@nutrien.com/work/seed-association-service/node_modules/axios-curlirize/src/main.js from /Users/justin.collum2@nutrien.com/work/seed-association-service/dist/dao.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 main.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/justin.collum2@nutrien.com/work/seed-association-service/node_modules/axios-curlirize/package.json.
// dao.ts
import axios from 'axios';
...
import curlirize from 'axios-curlirize';
console.log(curlirize); // this line was suggested in a different ticket
// curlirize(axios); // using this instead didn't change the error
$ versions
Node v14.19.1
NPM 6.14.16
Yarn 1.22.18
OS:
ProductName:    macOS
ProductVersion: 12.5.1
BuildVersion:   21G83
$ cat package.json | grep "axios"
        "axios": "~0.27.2",
        "axios-curlirize": "~2.0.0",
        "@types/axios-curlirize": "~1.3.2",
aladdin-add commented 2 years ago

it's a breaking change in v2. you could use axios-curlirize@1.3.7 if using cjs.