GithubHelp home page GithubHelp logo

Comments (11)

adrienjoly avatar adrienjoly commented on May 27, 2024 1

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.

Sorvereign avatar Sorvereign commented on May 27, 2024

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.

DianaIonita avatar DianaIonita commented on May 27, 2024

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.

jippy89 avatar jippy89 commented on May 27, 2024

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.

adrienjoly avatar adrienjoly commented on May 27, 2024

from npm-pdfreader.

jippy89 avatar jippy89 commented on May 27, 2024

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.

jippy89 avatar jippy89 commented on May 27, 2024

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.

adrienjoly avatar adrienjoly commented on May 27, 2024

this article may help: How to Create a Dual-Mode Cross-Runtime Package

from npm-pdfreader.

isimisi avatar isimisi commented on May 27, 2024

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.

VitorBrangioni avatar VitorBrangioni commented on May 27, 2024

Any date to fix this issue? The @isimisi pr from pdf2json has been merged

from npm-pdfreader.

adrienjoly avatar adrienjoly commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.