Select to view content in your preferred language

SyntaxError: Cannot use import statement outside a module (TypeScript)

899
1
Jump to solution
02-27-2024 09:08 PM
GeeteshSingh07
Occasional Contributor II

Getting this error when debugging 'widget.tsx' file:

import { AllWidgetProps, jsx, React } from 'jimu-core'; ^^^^^^ SyntaxError: Cannot use import statement outside a module at Object.compileFunction (node:vm:352:18) at wrapSafe (node:internal/modules/cjs/loader:1033:15) at Module._compile (node:internal/modules/cjs/loader:1069:27) at Module._extensions..js (node:internal/modules/cjs/loader:1159:10) at Object.require.extensions.<computed> [as .js] (C:\Users\arcgis-experience-builder-1.12\ArcGISExperienceBuilder\node_modules\ts-node\src\index.ts:16...) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) at node:internal/main/run_main_module:17:47

source-map-support.js:726


I have tried modifying package.json (adding/removing "type":"module" & tsconfig.json , tried 
"module" as various parameters, but nothing works.
 

 

  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "module": "CommonJS",
    "moduleResolution": "node",
    "target": "es6",
    "esModuleInterop": true,
    "lib": [
      "dom",
      "es6",
      "scripthost"
    ],
    "jsx": "react",

 

I've tried many suggestions from various sources but nothing works..

Any help on this will really be appreciated.

Thank you

0 Kudos
1 Solution

Accepted Solutions
GeeteshSingh07
Occasional Contributor II

I was able to resolve this by re-installation of npm & Node.js. I kept "type":"module" in package.json.

View solution in original post

0 Kudos
1 Reply
GeeteshSingh07
Occasional Contributor II

I was able to resolve this by re-installation of npm & Node.js. I kept "type":"module" in package.json.

0 Kudos