LoginSignup
4
5

More than 3 years have passed since last update.

`SyntaxError: Cannot use import statement outside a module` JSでimportの箇所でエラー起きる

Posted at

エラー

(node:211) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
~/getMessageOnSlack.js:1
import axios from 'axios';
^^^^^^

SyntaxError: Cannot use import statement outside a module

解決法

エラーが言っているように、package.jsonにtype:module を追加するだけ

package.json
{
  "name": "",
   .
   .
   .
  "type": "module",
}

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5