Closed DianaIonita closed 3 months ago
I just resolve this issue using firebase cloud functions
I'm using node@18.15.0, set this to your package.json
"type: "module""
Since your working with Typescript, try this config to your tsconfig.ts
{ "compilerOptions": { "module": "ES2022", "noImplicitReturns": true, "moduleResolution": "Node16", "noUnusedLocals": true, "outDir": "lib", "sourceMap": true, "strict": true, "target": "es2017" }, "compileOnSave": true, "include": [ "src" ] }
Vscode could help you resolve some import issues :)
I just resolve this issue using firebase cloud functions
I'm using node@18.15.0, set this to your package.json
"type: "module""
Since your working with Typescript, try this config to your tsconfig.ts
{ "compilerOptions": { "module": "ES2022", "noImplicitReturns": true, "moduleResolution": "Node16", "noUnusedLocals": true, "outDir": "lib", "sourceMap": true, "strict": true, "target": "es2017" }, "compileOnSave": true, "include": [ "src" ] }
Vscode could help you resolve some import issues :)
Thanks for your help, @Sorvereign, but it doesn't solve my problem.
I did as you suggested, updated package.json
and tsconfig.json
, then compiled the typescript file and:
.../read-pdf.js:2
Object.defineProperty(exports, "__esModule", { value: true });
^
ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '...\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
I took the hint and renamed the compiled js file to read-pdf.cjs
and tried:
> node read-pdf.cjs
...\read-pdf.cjs:3
var pdfreader_1 = require("pdfreader");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module ...\node_modules\pdfreader\index.js from ...\read-pdf.cjs not supported.
Instead change the require of index.js in ...\read-pdf.cjs to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (...\read-pdf.cjs:3:19) {
code: 'ERR_REQUIRE_ESM'
}
I used NodeJS 18.17.1, I've tried using the following setup and it worked.
Add type: module
to your package.json
And for tsconfig.json
, you should add the following
{
"module": "ES2022",
"moduleResolution": "Node",
}
Good job!
Would you be interested to submit these changes in a pull request?
Adrien
Le ven. 1 sept. 2023 à 17:05, Jip Irfandy @.***> a écrit :
I used NodeJS 18.17.1, I've tried using the following setup and it worked.
Add type: module to your package.json
And for tsconfig.json, you should add the following
{ "module": "ES2022", "moduleResolution": "Node",}
— Reply to this email directly, view it on GitHub https://github.com/adrienjoly/npm-pdfreader/issues/133#issuecomment-1702902258, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEB2ROY7TQLYQFS7NW5XITXYH2T5ANCNFSM6AAAAAA2E2QDXI . You are receiving this because you are subscribed to this thread.Message ID: @.***>
Thanks for the offer! I'll gladly help, but I currently have my hands full right now. But maybe if we choose to use this library in the future, I might be able to help.
Maybe for others, from what I've looked, and basically, the problem is, that the package did not support CommonJS, which is the default module used by TypeScript settings. It could be a concern since it's a default TypeScript setting after all. So to fix those things up, I just changed my TypeScript settings to use ES Modules instead of CommonJS.
this article may help: How to Create a Dual-Mode Cross-Runtime Package
I tried to rollup to cjs, however pdf2json has the same issue - so before this package can rollup to cjs, pdf2json has to do that aswell. At least as far as I could tell
update: I've created a PR in pdf2json
Any date to fix this issue? The @isimisi pr from pdf2json has been merged
I don't have time to do it at the moment. Feel free to send a pull request, I'll review and merge it.
Hi all!
@kvnglvz just sent a PR intending to fix that problem. (See the mention above this message)
Can any of you test it in their project and/or provide review suggestions on how to improve it before merging it, please?
(On the top of my head, I would prefer to reduce the number of changes, e.g. avoid duplicating the contents of index.js and/or updating so many deps)
@adrienjoly I created another PR to address this topic without having the index file duplicated in the repo. Would be great to get this reviewed and merged :)
I tested with my typescript project locally and it resolved the issues I had.
Should be fixed now that #156 was merged.
=> released in v3.0.3.
Thank you for your contribution, Pipo93!
Describe the bug I am unable to import or require the module to use in my nodejs application.
To Reproduce
Create a typescript file (I named it
read-pdf.ts
).I then ran
which generated:
Then finally,
Expected behavior I expected the program to run without errors.
Screenshots, outputs or logs
Desktop (please complete the following information):
~- OS: (e.g. iOS)~ ~- Browser: (e.g. chrome, safari)~ ~- Version: (e.g. 22)~
Using nodejs 16.16.0, server side only, no browser required. Intended to run across OSes.