question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

next js - error: Cannot use import statement outside a module

See original GitHub issue

I have a very simple fetcher that I’m setting up like so:

import ky from 'ky-universal';

const fetchFromApi = ky.extend({
  prefixUrl: process.env.BE_API_ROOT_DOMAIN,
});

export default fetchFromApi;

Which is giving the following error:

Screen Shot 2021-01-15 at 17 17 57

Can’t put my finger on it… Any ideas?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
sholladaycommented, Jan 29, 2021

@husayt that’s what we had previously. You can use ky-universal v0.8.2 or below if you need CommonJS support. We dropped it because Node 14 and above support ES modules and that’s what everything should be going forward. That matters because as of last October, Node 14 is the active LTS version. We waited long enough, it is time for the community to make the transition. Tell the Next.js folks you want ESM support.

0reactions
sholladaycommented, Feb 13, 2021

@rommyarb yes, I would recommend doing npm install ky@0.25 ky-universal@0.8

Those versions support CommonJS and should work fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] NextJS: SyntaxError: Cannot use import statement ...
It means that we cannot add redirect to appropriate types of given path (at the moment package.json supports only one types file/path). Only ......
Read more >
"Cannot use import statement outside a module" error when ...
The error occurs because react-hook-mousetrap is exported as an ESM library. You can have Next.js transpile it using next-transpile-modules ...
Read more >
How to fix "cannot use import statement outside a module"
I stumbled on this error: Uncaught SyntaxError: cannot use import statement outside a module while importing a function from a JavaScript file.
Read more >
Cannot use import statement outside a module [React ...
In this article, we talked about the SyntaxError: Cannot use import statement outside a module error in TypeScript and JavaScript. This error ...
Read more >
SyntaxError: Cannot use import statement outside a module
This is an issue with NextJs and SSR. In order to resolve the issue you need to import the module with dynamic on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found