Laravel-mix: Build Error - unexpected token =

Created on 20 Oct 2020  ·  10Comments  ·  Source: JeffreyWay/laravel-mix

  • Laravel Mix Version: 6.0.0-beta.10 (npm list --depth=0)
  • Node Version (node -v): 10.15.0
  • NPM Version (npm -v): 6.4.1
  • OS: OSX 10.14.6

Description:

Running npm run development npm run watch npm run production returns an error.

static testing = false; Unexpected token = (Full error below)

I attempted to comment out that line and another error was returned:
static fakedLogs = []; Unexpected token =

Full Error: [webpack-cli] /sites/firstquoteinsurance/node_modules/laravel-mix/src/Log.js:5
static testing = false;
^

SyntaxError: Unexpected token =
at new Script (vm.js:79:7)
at NativeCompileCache._moduleCompile (/sites/firstquoteinsurance/node_modules/v8-compile-cache/v8-compile-cache.js:242:18)
at Module._compile (/sites/firstquoteinsurance/node_modules/v8-compile-cache/v8-compile-cache.js:186:36)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (/sites/firstquoteinsurance/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
at Object. (/sites/firstquoteinsurance/node_modules/laravel-mix/src/webpackPlugins/CustomTasksPlugin.js:1:73)

Steps To Reproduce:

Upgrade to laravel-mix@next, run new development script npm run development.

I've removed my node_modules folder, package-lock.json, and added the new scripts from upgrade.md to the package.json file.

Package.json - "devDependencies": {
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"cross-env": "^7.0",
"laravel-mix": "^6.0.0-beta.10",
"less": "^3.12.2",
"less-loader": "^7.0.1",
"resolve-url-loader": "^3.1.0",
"vue-template-compiler": "^2.6.12"
},
"dependencies": {
"@gerhobbelt/markdown-it-attrs": "^3.0.3-20",
"@mdi/svg": "^5.5.55",
"alpinejs": "^2.7.0",
"axios": "^0.19",
"babel-plugin-webpack-alias": "^2.1.2",
"fontfaceobserver": "^2.1.0",
"lodash": "^4.17.19",
"markdown-it": "^11.0.0",
"markdown-it-container": "^3.0.0",
"normalize.css": "^8.0.1",
"tiny-slider": "^2.9.3",
"web-vitals": "^0.2.4"
}

npm list -
├── @babel/[email protected]
├── @gerhobbelt/[email protected]
├── @mdi/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── normalize.[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

npm ERR! peer dep missing: webpack@^4.0.0, required by [email protected]
npm ERR! peer dep missing: webpack@^4.0.0, required by [email protected]

Most helpful comment

I had the same problem, upgrading to the latest version of node (v15.0) fixed this issue for me.

All 10 comments

I had the same problem, upgrading to the latest version of node (v15.0) fixed this issue for me.

Yep, you're on an old version of Node. End of life for Node v10 is this coming April. Go ahead and update.

Just ran into this one myself. The problem is that Ubuntu 20.04 (LTS released this April) is on node 10!

Don't be surprised if this one starts cropping up more and more often.

Perfectly worked for me

@JeffreyWay I am on Node v15.5 and it still crops up

> @ dev /Users/aligajani/Sites/paperless
> npm run development


> @ development /Users/aligajani/Sites/paperless
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --config=node_modules/laravel-mix/setup/webpack.config.js

[webpack-cli] /Users/aligajani/Sites/paperless/node_modules/laravel-mix/src/Log.js:5
    static testing = false;
                   ^

SyntaxError: Unexpected token =
    at new Script (vm.js:85:7)
    at NativeCompileCache._moduleCompile (/Users/aligajani/Sites/paperless/node_modules/v8-compile-cache/v8-compile-cache.js:240:18)
    at Module._compile (/Users/aligajani/Sites/paperless/node_modules/v8-compile-cache/v8-compile-cache.js:184:36)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Module.require (internal/modules/cjs/loader.js:723:19)
    at require (/Users/aligajani/Sites/paperless/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/Users/aligajani/Sites/paperless/node_modules/laravel-mix/src/webpackPlugins/CustomTasksPlugin.js:1:73)
    at Module._compile (/Users/aligajani/Sites/paperless/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the @ development script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/aligajani/.npm/_logs/2021-01-03T12_20_17_069Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the @ dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/aligajani/.npm/_logs/2021-01-03T12_20_17_117Z-debug.log

I had similar issue. I just fixed it now.

My nodejs version was 10.*
I had to use this link to update my nodejs.

After doing that, everything worked perfectly!

You can also use nvm to manage the Node versions in your SO, it's quite simple to use. The nvm purpose is to allow you to install and manage the use of multiple version of Node (and consequently, npm)

For Linux and macOS: https://github.com/nvm-sh/nvm

For Windows: https://github.com/coreybutler/nvm-windows

C:UsersAbdullahDownloadsCompressedcmderlaravel-qa (lesson-6)
λ npm run dev

@ dev C:UsersAbdullahDownloadsCompressedcmderlaravel-qa
npm run development

@ development C:UsersAbdullahDownloadsCompressedcmderlaravel-qa
mix

ERROR in ./resources/js/components/ExampleComponent.vue 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. S
ee https://webpack.js.org/concepts#loaders