thekevinscott / UpscalerJS

Enhance Images with Javascript and AI. Increase resolution, retouch, denoise, and more. Open Source, Browser & Node Compatible, MIT License.
https://upscalerjs.com
MIT License
778 stars 73 forks source link

ES module #1184

Closed Rstacx closed 11 months ago

Rstacx commented 11 months ago

When I imported the upscaler package and started it, I got this error Please tell me how to fix this

import upscaler from "upscaler";

/root/pro/node_modules/upscaler/dist/browser/esm/index.js:1
export { default, } from './upscaler';
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1153:20)                                                    at Module._compile (node:internal/modules/cjs/loader:1205:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at cjsLoader (node:internal/modules/esm/translators:283:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:233:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)

Node.js v20.6.1
thekevinscott commented 11 months ago

If you're running in Node, you'll want to import the node-specific package:

import upscaler from "upscaler/node";

You can check out this example for more guidance.

If you're not in Node then please let me know more information about the environment you're in, the bundler you're using, etc.

thekevinscott commented 11 months ago

Feel free to re-open this ticket with more information about your platform / build setup. Ideal would be to reproduce the issue in a standalone repo or codesandbox example.

adityapatadia commented 10 months ago

When we tried this import Upscaler from 'upscaler/node'; it throws error Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './node' is not defined by "exports" in

thekevinscott commented 10 months ago

@adityapatadia Can you provide a bit more context on your environment?

If you're using import, I assume you're either using ts-node or you're using ESM modules in Node.

The node packages only support common js, which means you need to require() them. I added more context here:

https://github.com/thekevinscott/UpscalerJS/issues/554#issuecomment-1344108954

If you're using ts-node, I believe there is a tsconfig setting I can try and dig up that enables cross-compatibility (so you can do an import on a CJS module).

If you are trying to use ESM modules, let me know. I made an issue to add support for ESM in node here (https://github.com/thekevinscott/UpscalerJS/issues/671) but dropped it as I got the sense it wasn't in high demand. If it's something you need I can pick it up again.

adityapatadia commented 10 months ago

We are using ESM on nodejs. Require does not work there and there does not seem to be a workaround.

thekevinscott commented 10 months ago

@adityapatadia let's move this comment thread to #671