RienNeVaPlus / wikifolio

📊 Wikifolio (unofficial) API
18 stars 6 forks source link

Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. #12

Closed coveritytest closed 2 years ago

coveritytest commented 2 years ago

I have some issues to get this running. I'm new to nodejs, so maybe I'm doing something wrong here. That's what I do on Ubuntu:

sudo npm install --global yarn
mkdir build; cd build
cat <<EOF >>wiki.ts
import Api from 'wikifolio'
const api = new Api({email: 'example@riennevaplus.de', password: 'examplepassword1337'})
EOF
sudo yarn init
sudo yarn add wikifolio
node wiki.ts
(node:4566) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/home/m/Desktop/build/wiki.ts:1
import Api from 'wikifolio'
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47

Some sort of import error, but I don't know what I'm missing.

jekru commented 2 years ago

Add "type": "module" to your package.json

{
  "name": "Wikifolio Example",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
+  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "wikifolio": "^0.3.3"
  }
}
- import Api from 'wikifolio'
+ import { Api } from 'wikifolio'

const api = new Api({email: 'example@riennevaplus.de', password: 'examplepassword1337'})
coveritytest commented 2 years ago

Thanks a lot, @jekru!