nbesli/pdf-merger-js

Error [ERR_REQUIRE_ESM]: require() of ES Module

Closed this issue · 4 comments

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)

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

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'

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 ?

If you need legacy (CommonJS) support please use Version 4: "pdf-merger-js": "^4".
Since Version 5 this library only supports the ESM modules standard!