Error (es2015 not found) running "npm run dev" on a laravel homestead

504 views Asked by At

Struggling with Laravel 5.4 vagrant box on Windows 10, trying to get laravel-mix to work. My end goal is to set up a ServiceWorker and asset caching for a PWA (Progressive Web App), and must admit node, npm, mix/gulp are puzzling me. From what I see in forum posts, it is rather fragile technology, susceptible to breaks with any minor change or variation on the environment.

I get this error message 4 times when running "npm run dev" (once for each compiled js resource):

Module build failed: Error: Couldn't find preset "es2015" relative to directory "/home/vagrant"
at /home/vagrant/Code/laravel-basics/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19

Here is my package.json:

{ 
  "private": true,
  "scripts": {
    "dev": "npm run development",
    "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "development2": "./node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch-poll": "npm run watch -- --watch-poll",
    "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "prod": "npm run production",
    "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },
  "devDependencies": {
    "axios": "^0.16.2",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "bootstrap-sass": "^3.3.7",
    "cross-env": "^5.0.5",
    "font-awesome": "^4.7.0",
    "jquery": "^3.1.1",
    "laravel-mix": "^1.4.2",
    "lodash": "^4.17.4",
    "node-sass": "^4.5.3",
    "sw-precache-webpack-plugin": "^0.11.4",
    "vue": "^2.1.10",
    "webpack-rtl-plugin": "^1.5.0"
  }
}

The latest attempt was running vagrant from an Administrator Command prompt before doing "rm -rf node_modules && npm install" (or its equivalent). I don't like this but the npm install went a lot smoother than with "--no-bin-links" options. I also tried yarn instead of npm install.

2

There are 2 answers

1
Ihor On BEST ANSWER

That should fix it. Don't forget to include a .babelrc with

{
  "presets": ["es2015"]
}
0
flap152 On

I tried many things but it seems the combination of

  • Running Vagrant/Homestead as Administrator in command prompt
  • Installing es2015 globally, in addition to --no-bin-links
  • Restarting the VM so the global install with environment changes takes effect
  • THEN, npm run dev

did the trick. I tried this sequence on a new laravel project on the same machine. Hopefully it will also work when I destroy my VM and redo this...