SyntaxError: Cannot use import statement outside a module when run gulp server / gulp watch in my ruby project
Asked Answered
S

2

5

On my ruby project when I try to run gulp (gulp server, gulp watch) I have the following error :

Users/workspace/website2019/gulpfile.babel.js:1
import del from 'del';
^^^^^^

SyntaxError: Cannot use import statement outside a module

I don't get how can I fix it, if someone could help me please,

Slit answered 28/1, 2020 at 14:27 Comment(0)
K
6

make sure you have this line in package.json

"type": "module"
Kiva answered 3/6, 2022 at 17:38 Comment(0)
L
4

you use babel transpilation with gulp because of the file gulpfile.babel.js For this reason you need to install babel. according to the documentation you need @babel/register and @babel/preset-env for transpiling your import syntax.

So run the following command in your project folder

npm install --save-dev @babel/core @babel/register

Afterwards create the babel configuration file .babelrc in the root folder and add the following lines to it

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": "current"
        }
      }
    ]
  ]
}
Leghorn answered 2/3, 2020 at 8:12 Comment(1)
This solution should be for gulp-v4.0 and above.Neuritis

© 2022 - 2024 — McMap. All rights reserved.