I have encountered the exact same error attempting to import the UploadClient module as well as the @uploadcare/react-widget module.
My stack is node.js 14LTS with React over next.js.
I have attempted to import using a standard import statement, import() function, as well as next/dynamic. Each behaves the same way and results in a similar stack with the same error message.
I can't use the 2nd method, for obvious reasons, but it seems like the importer is choosing the wrong file to import for some reason.
{
"name": "sim",
"version": "1.0.0",
"description": "",
"main": "src/server.mjs",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "next build",
"start": "node src/server.mjs",
"dev": "nodemon src/server.mjs -e json,js,cjs,mjs",
"remoteDev": "nodemon -- --inspect=0.0.0.0:9229 src/server.mjs -e json,js,cjs,mjs"
},
"author": "Ronald Barbosa <[email protected]>",
"license": "UNLICENSED",
"dependencies": {
"@omarmfs98/nextjs-orgchart": "^1.0.8",
"@sendgrid/mail": "^7.6.2",
"@uploadcare/react-widget": "^2.2.0",
"@uploadcare/upload-client": "^5.1.0",
"ajv": "^8.11.0",
"axios": "^0.21.4",
"bcrypt": "^5.0.1",
"copy-webpack-plugin": "^10.2.4",
"formidable": "^2.0.1",
"graphql": "^15.5.1",
"iron-session": "^6.1.3",
"mongo-sanitize": "^1.1.0",
"mongoose": "^5.13.0",
"next": "^11.0.1",
"next-connect": "^0.12.2",
"next-routes": "^1.4.2",
"qrcode": "^1.5.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^2.0.3",
"speakeasy": "^2.0.0",
"tesseract.js": "^2.1.5",
"validator": "^13.7.0"
},
"devDependencies": {
"nodemon": "^2.0.8"
}
}
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /com.omnivertical.apps/sim/node_modules/@uploadcare/upload-client/dist/index.node.js
require() of ES modules is not supported.
require() of /com.omnivertical.apps/sim/node_modules/@uploadcare/upload-client/dist/index.node.js from /com.omnivertical.apps/sim/.next/server/pages/api/passport/create.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.node.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /com.omnivertical.apps/sim/node_modules/@uploadcare/upload-client/package.json.
at new NodeError (<node_internals>/internal/errors.js:322:7)
at Object.Module._extensions..js (<node_internals>/internal/modules/cjs/loader.js:1102:13)
at Module.load (<node_internals>/internal/modules/cjs/loader.js:950:32)
at Function.Module._load (<node_internals>/internal/modules/cjs/loader.js:790:12)
at Module.require (<node_internals>/internal/modules/cjs/loader.js:974:19)
at require (<node_internals>/internal/modules/cjs/helpers.js:101:18)
at Object.@uploadcare/upload-client (/com.omnivertical.apps/sim/.next/server/pages/api/passport/create.js:132:18)
at __webpack_require__ (/com.omnivertical.apps/sim/.next/server/webpack-runtime.js:33:42)
at eval (webpack-internal:///./src/pages/api/passport/create.js:12:83)
at Object../src/pages/api/passport/create.js (/com.omnivertical.apps/sim/.next/server/pages/api/passport/create.js:88:1)
at __webpack_require__ (/com.omnivertical.apps/sim/.next/server/webpack-runtime.js:33:42)
at __webpack_exec__ (/com.omnivertical.apps/sim/.next/server/pages/api/passport/create.js:230:52)
at /com.omnivertical.apps/sim/.next/server/pages/api/passport/create.js:231:28
at Object.<anonymous> (/com.omnivertical.apps/sim/.next/server/pages/api/passport/create.js:234:3)
at Module._compile (<node_internals>/internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (<node_internals>/internal/modules/cjs/loader.js:1114:10)