Gedeon Mutshipayi
Gedeon Mutshipayi

Reputation: 4083

Uncaught: SyntaxError: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import

I'm trying to publish an npm package, when testing locally during an import of my package I get the following error :

Uncaught: SyntaxError: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import

This is my package.js content :

{
  "name": "gedflod",
  "version": "0.0.1",
  "description": "A gedflod nodejs package for doing some thing",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/ged-flod/gedflod.git"
  },
  "keywords": [
    "ged",
    "flod",
    "ged-flod",
    "gedflod",
  ],
  "author": "ged-flod",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/ged-flod/gedflod/issues"
  },
  "homepage": "https://github.com/ged-flod/gedflods#readme",
  "dependencies": {
    "axios": "^0.26.0"
  }
}

Can someone you help me.

Upvotes: 3

Views: 3625

Answers (1)

emont01
emont01

Reputation: 3230

As indicated in another response you need to call the import function:

$ node
Welcome to Node.js v16.6.0.
Type ".help" for more information.
> const {myFunction} = await import('./src/myFunction.js')
> myFunction(...)

I understand this works since Node.js 13 but I can only confirm it works in Node.js v16.6.0

Upvotes: 2

Related Questions