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 #31

Closed
matveychuk opened this issue Jan 17, 2021 · 2 comments
Closed

Must use import to load ES Module #31

matveychuk opened this issue Jan 17, 2021 · 2 comments

Comments

@matveychuk
Copy link

When trying to use ky/ky-universal with the newly created Next.js app receive such error:
Error: Must use import to load ES Module: /Users/---/node_modules/ky-universal/index.js
require() of ES modules is not supported.
require() of /---/node_modules/ky-universal/index.js from /---/.next/server/pages/index.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 /---/node_modules/ky-universal/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /---/node_modules/ky-universal/package.json.

Packages version:
Node 14.15.4,
"dependencies": {
"ky": "^0.26.0",
"ky-universal": "^0.9.1",
"next": "10.0.5",
"react": "17.0.1",
"react-dom": "17.0.1"
}

Code extract

import ky from "ky-universal";

export default function Home() {
  const fetchData = async () => {
    const res = await ky
      .get("https://jsonplaceholder.typicode.com/todos/1")
      .json();
    setData(res);
    console.log(res);
  };
@sindresorhus
Copy link
Owner

Duplicate of #30

@sindresorhus sindresorhus marked this as a duplicate of #30 Jan 17, 2021
@sindresorhus
Copy link
Owner

I would open an issue over at https://github.com/vercel/next.js This package is correctly set up for ESM, so Next.js is doing something wrong.

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