Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error [ERR_REQUIRE_ESM]: require() of ES Module #138

Open
uigyo opened this issue Mar 20, 2024 · 3 comments
Open

Error [ERR_REQUIRE_ESM]: require() of ES Module #138

uigyo opened this issue Mar 20, 2024 · 3 comments

Comments

@uigyo
Copy link

uigyo commented Mar 20, 2024

I deleted the library and when I reinstalled it, suddenly strange errors occurred.
I use nestjs. Please help me

"pdf-merger-js": "^5.1.1",
"node": "20.11.1",
yarn: 3.6.1,
"@nestjs/core": "^9.0.0",

tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowJs": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}

module.exports = require("pdf-merger-js");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/gim-uigyo/Documents/WORK/pdf/node_modules/pdf-merger-js/index.js from /Users/gim-uigyo/Documents/WORK/pdf/dist/main.js not supported.
Instead change the require of index.js in /Users/gim-uigyo/Documents/WORK/pdf/dist/main.js to a dynamic import() which is available in all CommonJS modules.
at pdf-merger-js (/Users/gim-uigyo/Documents/WORK/pdf/dist/main.js:1962:18)
at webpack_require (/Users/gim-uigyo/Documents/WORK/pdf/dist/main.js:2036:42)
at ./src/resources/pdf/services/pdf.service.ts (/Users/gim-uigyo/Documents/WORK/pdf/dist/main.js:1520:25)
at webpack_require (/Users/gim-uigyo/Documents/WORK/pdf/dist/main.js:2036:42)
at ./src/resources/pdf/pdf.controller.ts (/Users/gim-uigyo/Documents/WORK/pdf/dist/main.js:1051:23)

@sanket-ifinworth
Copy link

@uigyo I am also facing the same issue, can anyone help us out on this.

@sergomet
Copy link

the same issue, I quickly fix it with
yarn remove pdf-merger-js

put "pdf-merger-js": "^4.3.1" in package.json and run
'yarn'

@paranicistefan
Copy link

paranicistefan commented May 23, 2024

Also facing this issue. Changing the compiler from commonjs to ESNext(or any ES Modules compilers) seems to fix the issue, but now ran into another error

Error: Cannot find module '.../dist/app.module' imported from .../dist/main.js

For now, i also downgraded to 4.3.1, but i'd like to change my compiler settings, to import the dependencies as modules in the dist files ?

Anyone had a chance to play with the ts-config settings, in a nest.js app ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants