SoFunction
Updated on 2025-04-04

About the solution to the cross-platform operation problem of Vue project

Record the pitfall

A few days ago, I took over a Vue project from my colleague. (Ps: Just two weeks after joining the company, my brother also wrote a readMe specifically, thank you);

The problem is here. I clone the project from gitLab, and the node environment and other configurations have been made.

npm install
npm run dev

Unable to run, the error message is as follows:

> NODE_ENV=development webpack-dev-server --open --inline --hot
 
'NODE_ENV' is not an internal or external command, nor a runnable program
or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `NODE_ENV=development webpack-dev-server --open --inline --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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:

At first I thought it was a package problem, but there were errors and warnings about the package during installation. I used Google Dafa and read several blogs, but I didn’t say it in detail, although it was a small problem. (Ps: I am indeed a bit of a bit) Then there is no problem with the same node environment in the department. The blog is about the Mac platform and Windows problem.

"scripts": {
  "dev": "NODE_ENV=development webpack-dev-server --open --inline --hot",
  "build": "NODE_ENV=production webpack --progress --hide-modules"
 },

This is the writing of the configuration environment that comes with the project. The reason for the error is that the Windows platform does not support such writing. It is necessary to implement cross-platform implementation through cross-env, a module of node.

npm install cross-env

Just add cross-env:

 "scripts": {
  "dev": " cross-env NODE_ENV=development webpack-dev-server --open --inline --hot",
  "build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
 },

Againnpm run dev, run successfully.

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.