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

Must use import to load ES Module #17

Closed
IzioDev opened this issue Aug 26, 2021 · 4 comments
Closed

Must use import to load ES Module #17

IzioDev opened this issue Aug 26, 2021 · 4 comments

Comments

@IzioDev
Copy link

IzioDev commented Aug 26, 2021

Hello,

I just installed this package, which by the way, seems to be the only one that does truncation and is currently maintained.

However, I have an issue while using this package inside my Next.Js application (in Typescript).

Here is how I import the package :

import cliTruncate from "cli-truncate";
// I also tried
import * as cliTruncate from "cli-truncate";

And here is the error on runtime:

Error: Must use import to load ES Module: D:\workspace\my-app\node_modules\cli-truncate\index.js
require() of ES modules is not supported.
require() of D:\workspace\my-app\node_modules\cli-truncate\index.js from D:\workspace\my-app\packages\website\.next\server\pages\blog.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from D:\workspace\my-app\node_modules\cli-truncate\package.json.

Do you have any idea why is this happening?

@sindresorhus
Copy link
Owner

@IzioDev
Copy link
Author

IzioDev commented Aug 26, 2021

@sindresorhus As you can see, I'm not requiring. I'm using the import syntax to load ES module.

@sindresorhus
Copy link
Owner

Yes, but Next.js transpiles it down to require calls by default.

@IzioDev
Copy link
Author

IzioDev commented Aug 26, 2021

Alright. Will fork and adapt, thanks.

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

2 participants