Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES module #1184

Closed
Rstacx opened this issue Oct 8, 2023 · 6 comments
Closed

ES module #1184

Rstacx opened this issue Oct 8, 2023 · 6 comments
Assignees

Comments

@Rstacx
Copy link

Rstacx commented Oct 8, 2023

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
Copy link
Owner

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
Copy link
Owner

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
Copy link

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
Copy link
Owner

@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:

#554 (comment)

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 (#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
Copy link

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

@thekevinscott
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants