1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

gulp エラー対応:SyntaxError: Cannot use import statement outside a module

Posted at

#環境
・MacOS
・gulp v4.0.2
・node.js v14.4.0

#エラー発生タイミング
package.json作成、npm iコマンドでモジュールインストール後にgulp実行でエラー(SyntaxError: Cannot use import statement outside a module)発生

コンソール エラー
[21:29:01] Requiring external module babel-register
/Applications/MAMP/htdocs/fuelphp/gulpfile.babel.js:1
import gulp from 'gulp';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1116:16)
    at Module._compile (internal/modules/cjs/loader.js:1164:27)
    at loader (/Applications/MAMP/htdocs/fuelphp/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.<computed> [as .js] (/Applications/MAMP/htdocs/fuelphp/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (internal/modules/cjs/loader.js:1049:32)
    at Function.Module._load (internal/modules/cjs/loader.js:937:14)
    at Module.require (internal/modules/cjs/loader.js:1089:19)
    at require (internal/modules/cjs/helpers.js:73:18)
    at requireOrImport (/usr/local/lib/node_modules/gulp/node_modules/gulp-cli/lib/shared/require-or-import.js:19:11)
    at execute (/usr/local/lib/node_modules/gulp/node_modules/gulp-cli/lib/versioned/^4.0.0/index.js:37:3)

#原因
ディレクトリ配下に.babelrcを作成していなかった

.babelrc
{
  "presets": ["env"]
}

#対策
.babelrc作成後、再度gulpコマンド実行で問題なく動作した

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?