SyntaxError: Cannot use import statement outside a module
See original GitHub issueTrying to use Ionic with react framework, and when running a basic debug test, I get the following error:
Jest encountered an unexpected token
Details:
C:\Users\<User>\Documents\GitHub\<appname>\node_modules\@codetrix-studio\capacitor-google-auth\dist\esm\index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { registerPlugin } from '@capacitor/core';
^^^^^^
SyntaxError: Cannot use import statement outside a module
1 | import { IonButton, IonContent, IonHeader,IonInput,IonLoading,IonPage, IonTitle, IonToolbar, IonIcon} from '@ionic/react';
> 2 | import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';
| ^
3 | import { useEffect, useState } from 'react';
4 | import { loginUser } from '../firebaseConfig';
5 | import ExploreContainer from '../components/ExploreContainer';
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
at Object.<anonymous> (src/pages/Login.tsx:2:1)
This ONLY occurs when the capactior-google-auth plugin is used, when that’s taken out, the test runs fine, even though there are plenty of other code modules. Does anyone have any idea what’s causing this?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:14
Top Results From Across the Web
"Uncaught SyntaxError: Cannot use import statement outside ...
This means that you're using the native source code in an unaltered/unbundled state, leading to the following error: Uncaught SyntaxError: ...
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 ...
When building a web application, you may encounter the SyntaxError: Cannot use import statement outside a module error.
Read more >How to solve: cannot use import statement outside a module
When you see the error message Uncaught SyntaxError: cannot use import statement outside a module, it means you're using an import statement ......
Read more >SyntaxError: Cannot use import statement outside a module
If you are using node application and want to use the import statement, then you will also get the " Cannot use import...
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 FreeTop 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
Top GitHub Comments
All the node modules. Some times jest holds a cache somewhere inside node modules and certain changes might corrupt it.
I’m not sure if you should keep your jest config inside babel config? use jest.config.js or package.json for that instead? https://jestjs.io/docs/configuration
Also seems that you are using
ts-jest
as your transformer:"node_modules/variables/.+\\.(j|t)sx?$": "ts-jest"
I don’t think that obeys babel config. You needbabel-jest
for that.Running into the same issue for:
jest.config.js
tsconfig.spec.json
tsconfig.json
Right now everything passes except for Google Auth, and if I uncomment transformIgnorePattern or testPathIgnorePattern everything breaks. I’ve also tried removing rootDir.