next js - error: Cannot use import statement outside a module
See original GitHub issueI 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:
Can’t put my finger on it… Any ideas?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.@rommyarb yes, I would recommend doing
npm install ky@0.25 ky-universal@0.8
Those versions support CommonJS and should work fine.