Comments (12)
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.
You also need to do one of two things to use ESM modules with typescript:
- Change the package.json type to "module" to use ESM
-OR-
- 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.
@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.
@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.
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.
You've got the wrong path in the import. It should be:
import * as mupdf from "mupdf"
from mupdf.js.
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.
Have you configured the typescript module resolution to use "nodenext"?
from mupdf.js.
Create a tsconfig.json with the following:
{
"compilerOptions": {
"module": "nodenext"
}
}
from mupdf.js.
@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.
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.
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)
- Annotation: Free Text Callout API
- Annotation: Leader Line API
- Annotation: Leader Line Extension API
- Annotation: Measure API
- Annotations: Add API for "DS"
- OCR HOT 1
- DocumentWriter.close WASM RuntimeError HOT 10
- "Error: invalid page number: 2" HOT 7
- Page: Draw as SVG API HOT 5
- REST server should cache open documents
- REST server should rate limit fetches to third party server
- REST server should check HTTP error codes from fetch
- REST server should catch exceptions from WASM
- simple-viewer search always skips results from the current page HOT 2
- Rearrange exception HOT 1
- Issue converting pdf to png containing a graph with mupdf-wasm but works in mutools HOT 1
- document.resolveLink returns only page index rather than link destination object HOT 6
- Journal does not work as expected
- Link for outline requires both x and y coordinates in XYZ mode HOT 1
- mupdf not working with Next.js RouteHandler HOT 4
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 mupdf.js.