Code Monkey home page Code Monkey logo

Comments (12)

jamie-lemon avatar jamie-lemon commented on June 9, 2024 2

Hi Tarek,

Thanks for your message. The NPM version will be updated as soon as the next release of MuPDF happens ( hopefully sometime within the next couple of days ). We are basically ready to go, but as MuPDF.js depends on MuPDF itself we want to base the next release on the latest version. I'll leave this issue open and ping you once we release!

All the best,
Jamie

from mupdf.js.

ccxvii avatar ccxvii commented on June 9, 2024 1

You also need to do one of two things to use ESM modules with typescript:

  1. Change the package.json type to "module" to use ESM

-OR-

  1. Change the file suffix to "mts" instead of "ts"

The easiest way to do this (without changing your configuration files) is being very explicit in the tsc command:

tsc -m nodenext test.mts

from mupdf.js.

jamie-lemon avatar jamie-lemon commented on June 9, 2024

@thaoula Just a heads-up - it should be available in the next few days - will be a version 0.2.0 due to the upgrade to supporting Typescript! Watch this space!

from mupdf.js.

jamie-lemon avatar jamie-lemon commented on June 9, 2024

@thaoula Sooner than I thought - we have just published 0.2.0 to NPM! Also updated the documentation to include a "Getting Started with Node.js" section too - please see: https://mupdfjs.readthedocs.io/en/latest/how-to-guide/node/index.html

from mupdf.js.

thaoula avatar thaoula commented on June 9, 2024

Hi @jamie-lemon,

Many thanks for the update and the team's hard work.

I just installed 0.2.0 but had to use the import as follows -
import * as mupdf from 'mupdf/dist/mupdf'

However it does not work at runtime.
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/mupdf' is not defined by "exports" in /home/app/node_modules/mupdf/package.json

Regards,
Tarek

from mupdf.js.

ccxvii avatar ccxvii commented on June 9, 2024

You've got the wrong path in the import. It should be:

import * as mupdf from "mupdf"

from mupdf.js.

thaoula avatar thaoula commented on June 9, 2024

Hi @ccxvii,

I know it should be like that. However, when i do attempt to import it that way ... Vscode complains mupdf is not a module.

Regards,
Tarek

from mupdf.js.

ccxvii avatar ccxvii commented on June 9, 2024

Have you configured the typescript module resolution to use "nodenext"?

from mupdf.js.

ccxvii avatar ccxvii commented on June 9, 2024

Create a tsconfig.json with the following:

{
        "compilerOptions": {
                "module": "nodenext"
        }
}

from mupdf.js.

jamie-lemon avatar jamie-lemon commented on June 9, 2024

@thaoula I am also having a problem when I try to compile the TS - it can't find the import. A plain "mjs" file can though, will investigate further ...

from mupdf.js.

ccxvii avatar ccxvii commented on June 9, 2024

To summarize how to use this in a brand new project (foo in this example):

~ $ mkdir foo
~ $ cd foo
~/foo $ npm install mupdf
~/foo $ npm install typescript
~/foo $ echo '{"compilerOptions":{"module":"nodenext"}}' > tsconfig.json
~/foo $ echo 'import * as mupdf from "mupdf"; console.log(mupdf)' > test.mts
~/foo $ npx tsc
~/foo $ node test.mjs
~/foo $ code .

If you change the npm package type to "module" you can also use plain .ts file extension instead of .mts:

npm pkg set type=module

from mupdf.js.

jamie-lemon avatar jamie-lemon commented on June 9, 2024

Also updated the page here for future reference: https://mupdfjs.readthedocs.io/en/latest/how-to-guide/node/typescript/index.html

from mupdf.js.

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.