“Syntaxerror: Cannot Use Import Statement Outside a Module”: Occurs on Ubuntu, but Not on Windows

I work with this assembly:

It works for me on Windows. But on Ubuntu, right after the run command (gulp, or npm run dev, or yarn run dev) does not start and gives the following error:

paranoic:~/PhpstormProjects/20_18$ gulp
[14:27:25] Requiring external module @babel/register
/home/paranoic/PhpstormProjects/project10/gulpfile.babel.js:3
import gulp from "gulp";
^^^^^^

SyntaxError: Cannot use import statement outside a module

Everywhere they write that these are troubles with babel. But why are they on one OS and not the other?

I have already taken the following measures, but they did not work:

  • Just in case, I checked some other assembly is running on Ubuntu. There is an assembly without imports - it starts

  • I changed the version of node to the one that supports modules and added an entry "type": "module" to the package

What should I do to make the build work on Ubuntu?

6
James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article