Node: v18.16.1
pdf2json: 3.0.4
Using express with Typescript
When i normally import the package like import Pdfparser from 'pdf2json';, it throws the below error
const pdf2json_1 = __importDefault(require("pdf2json"));
[1] ^
[1]
[1] Error [ERR_REQUIRE_ESM]: require() of ES Module project\node_modules\pdf2json\pdfparser.js from project\dist\routes\master-data.js not supported.
[1] Instead change the require of pdfparser.js in project\dist\routes\master-data.js to a dynamic import() which is available in all CommonJS modules.
[1] at Object. (project\dist\routes\master-data.js:44:36)
[1] at Object. (project\dist\index.js:102:39) {
[1] code: 'ERR_REQUIRE_ESM'
[1] }
According to issue #282 , I tried to implement changes as suggested but I still got the following error.
[1] Object.defineProperty(exports, "__esModule", { value: true });
[1] ^
[1]
[1] ReferenceError: exports is not defined in ES module scope
[1] This file is being treated as an ES module because it has a '.js' file extension and 'project\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
[1] at file:///project/dist/index.js:37:23
[1] at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
Node: v18.16.1 pdf2json: 3.0.4 Using express with Typescript
When i normally import the package like (project\dist\routes\master-data.js:44:36)
[1] at Object. (project\dist\index.js:102:39) {
[1] code: 'ERR_REQUIRE_ESM'
[1] }
import Pdfparser from 'pdf2json';
, it throws the below error const pdf2json_1 = __importDefault(require("pdf2json")); [1] ^ [1] [1] Error [ERR_REQUIRE_ESM]: require() of ES Module project\node_modules\pdf2json\pdfparser.js from project\dist\routes\master-data.js not supported. [1] Instead change the require of pdfparser.js in project\dist\routes\master-data.js to a dynamic import() which is available in all CommonJS modules. [1] at Object.According to issue #282 , I tried to implement changes as suggested but I still got the following error.
[1] Object.defineProperty(exports, "__esModule", { value: true }); [1] ^ [1] [1] ReferenceError: exports is not defined in ES module scope [1] This file is being treated as an ES module because it has a '.js' file extension and 'project\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. [1] at file:///project/dist/index.js:37:23 [1] at ModuleJob.run (node:internal/modules/esm/module_job:194:25)