Comments (11)
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)
from npm-pdfreader.
I just resolve this issue using firebase cloud functions
I'm using [email protected], 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 :)
from npm-pdfreader.
I just resolve this issue using firebase cloud functions
I'm using [email protected], 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'
}
from npm-pdfreader.
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",
}
from npm-pdfreader.
from npm-pdfreader.
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.
from npm-pdfreader.
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.
from npm-pdfreader.
this article may help: How to Create a Dual-Mode Cross-Runtime Package
from npm-pdfreader.
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
from npm-pdfreader.
Any date to fix this issue? The @isimisi pr from pdf2json has been merged
from npm-pdfreader.
I don't have time to do it at the moment. Feel free to send a pull request, I'll review and merge it.
from npm-pdfreader.
Related Issues (20)
- ReferenceError: MozBlobBuilder is not defined HOT 1
- example not working as shown in the document HOT 4
- PDF parse failed HOT 11
- Question: Missing spaces in text output HOT 1
- Can't import library: Unexpected token '(' HOT 7
- 'ava' is not recognized as an internal or external command - When testing compatibility HOT 5
- Clarification on latest release of pdfreader HOT 2
- Gettin items as promise HOT 1
- Make it async // return item as promise HOT 3
- Importing module failed HOT 4
- It is not supporting the TS type declaration. HOT 24
- aws lambda, sst. Error: Identifier '__dirname' has already been declared HOT 2
- Rules not working
- Import when using the library in Cypress HOT 1
- Can I get the coordinates of the given text from all pages of the PDF?
- Setting up fake worker.
- Cannot read text based PDF file content HOT 4
- Where is `displayValue` declared? HOT 1
- isDebugMode - No such file or directory "test\data\05-versions-space.pdf" HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from npm-pdfreader.