PS C:\Users\wangting\Desktop\assets_web_admin\assets_web_admin> npm run dev > vue-element-admin@4.2.1 dev C:\Users\wangting\Desktop\assets_web_admin\assets_web_admin > vue-cli-service serve INFO Starting development server... 10% building 2/2 modules 0 active ERROR SyntaxError: Cannot use import statement outside a module C:\Users\wangting\Desktop\assets_web_admin\assets_web_admin\mock\index.js:1 import "core-js/modules/es6.regexp.constructor"; ^^^^^^ SyntaxError: Cannot use import statement outside a module at wrapSafe (internal/modules/cjs/loader.js:1072:16) at Module._compile (internal/modules/cjs/loader.js:1122:27) at Module._compile (C:\Users\wangting\Desktop\assets_web_admin\assets_web_admin\node_modules\pirates\lib\index.js:99:24) at Module._extensions..js (internal/modules/cjs/loader.js:1178:10) at Object.newLoader [as .js] (C:\Users\wangting\Desktop\assets_web_admin\assets_web_admin\node_modules\pirates\lib\index.js:104:7) at Module.load (internal/modules/cjs/loader.js:1002:32) at Function.Module._load (internal/modules/cjs/loader.js:901:14) at Module.require (internal/modules/cjs/loader.js:1044:19) at require (internal/modules/cjs/helpers.js:77:18) at registerRoutes (C:\Users\wangting\Desktop\assets_web_admin\assets_web_admin\mock\mock-server.js:11:30) at Object.module.exports [as before] (C:\Users\wangting\Desktop\assets_web_admin\assets_web_admin\mock\mock-server.js:57:22) at Object.before (C:\Users\wangting\Desktop\assets_web_admin\assets_web_admin\node_modules\@vue\cli-service\lib\commands\serve.js:165:67) at Server.setupBeforeFeature (C:\Users\wangting\Desktop\assets_web_admin\assets_web_admin\node_modules\webpack-dev-server\lib\Server.js:455:18) at Object.before (C:\Users\wangting\Desktop\assets_web_admin\assets_web_admin\node_modules\webpack-dev-server\lib\Server.js:515:16) at C:\Users\wangting\Desktop\assets_web_admin\assets_web_admin\node_modules\webpack-dev-server\lib\Server.js:584:24 at Array.forEach (<anonymous>)
原来是我在写代码的时候
不小心删掉了这段代码
打开
环境配置.env.development文件
在最后面加上
VUE_CLI_BABEL_TRANSPILE_MODULES = true
这个文件完整的代码如下
还是改一下随手乱动代码的习惯吧~~~
# just a flag ENV = 'development' # base api VUE_APP_BASE_API = '/dev-api' # vue-cli uses the VUE_CLI_BABEL_TRANSPILE_MODULES environment variable, # to control whether the babel-plugin-dynamic-import-node plugin is enabled. # It only does one thing by converting all import() to require(). # This configuration can significantly increase the speed of hot updates, # when you have a large number of pages. # Detail: https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/babel-preset-app/index.js VUE_CLI_BABEL_TRANSPILE_MODULES = true
再次执行
npm run dev
即可运行成功了