关于 Module build failed: ReferenceError: Promise is not defined 错误

本文详细介绍了Webpack打包时报错的原因及解决方案,具体为Node.js版本过低导致css-loader依赖的postcss插件无法正常工作。通过升级Node.js版本至5.0稳定版,成功解决了此问题,确保了Webpack打包任务顺利完成。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

webpack打包的时候报错:Module build failed: ReferenceError: Promise is not defined
</pre><pre name="code" class="java">ERROR in ./~/css-loader!./style.css  
Module build failed: ReferenceError: Promise is not defined  
    at LazyResult.async (D:\js\react\tutorial1-webpack\node_modules\css-loader\node_modules\postcss\lib\lazy-result.js:152:31)  
    at LazyResult.then (D:\js\react\tutorial1-webpack\node_modules\css-loader\node_modules\postcss\lib\lazy-result.js:75:21)  
    at processCss (D:\js\react\tutorial1-webpack\node_modules\css-loader\lib\processCss.js:181:5)  
    at Object.module.exports (D:\js\react\tutorial1-webpack\node_modules\css-loader\lib\loader.js:24:2)  
 @ ./style.css 4:14-73  


原因:

    安装的node.js版本过低,而css-loader依赖的postcss插件最低node.js版本要求是0.12.故引起webpack执行报错。

解决方案:

    升级nodejs版本,去官网下载最新的5.0稳定版,然后安装,查看版本, v5.0.0

退出重新运行: webpack,打包成功,页面正常使用。



/node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0&bustCache!./src/views/modules/cmmsEquipmentInfo/cmmsEquipmentInfoDetail.vue Module build failed: SyntaxError: E:/AJR/code/techService/front/src/views/modules/cmmsEquipmentInfo/cmmsEquipmentInfoDetail.vue: Unexpected token, expected => (300:29) 298 | }; 299 | // 新增方法:加载设备详情 > 300 | async loadEquipmentDetail(equipmentId) { | ^ 301 | try { 302 | // 调用获取设备详情的API 303 | const response = await getEquipmentDetail(equipmentId); @ ./src/views/modules/cmmsEquipmentInfo/cmmsEquipmentInfoDetail.vue 8:0-152 @ ./src/views ^\.\/.*\.vue$ @ ./src/router/import-development.js @ ./src/router/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://127.0.0.1:9001 webpack/hot/dev-server babel-polyfill ./src/main.js errors @ client:139 (匿名) @ socket.js:37 (匿名) @ eventtarget.js:51 (匿名) @ main.js:274 (匿名) @ main.js:272 (匿名) @ emitter.js:50 (匿名) @ websocket.js:35 cmmsEquipmentInfoDetail.vue:321 请求设备详情失败: ReferenceError: getEquipmentDetail is not defined at VueComponent._callee2$ (cmmsEquipmentInfoDetail.vue:308:1) at tryCatch (runtime.js:62:15) at Generator.invoke [as _invoke] (runtime.js:296:1) at Generator.next (runtime.js:114:1) at step (asyncToGenerator.js:17:1) at asyncToGenerator.js:35:1 at new Promise (<anonymous>) at new F (_export.js:36:1) at asyncToGenerator.js:14:1 at VueComponent.loadEquipmentDetail (cmmsEquipmentInfoDetail.vue:324:1)
06-11
=> ERROR [vue_app build 6/6] RUN npm run build 8.7s ------ > [vue_app build 6/6] RUN npm run build: 0.579 0.579 > vue_learn@0.0.0 build 0.579 > vue-tsc -b && vite build 0.579 8.514 ▲ [WARNING] The CommonJS "module" variable is treated as a global variable in an ECMAScript module and may not work as expected [commonjs-variable-in-esm] 8.514 8.514 vite.config.ts:32:0: 8.514 32 │ module.exports = { 8.514 ╵ ~~~~~~ 8.514 8.514 This file is considered to be an ECMAScript module because of the "export" keyword here: 8.514 8.514 vite.config.ts:6:0: 8.514 6 │ export default defineConfig({ 8.514 ╵ ~~~~~~ 8.514 8.610 failed to load config from /app/vite.config.ts 8.615 error during build: 8.615 ReferenceError: module is not defined in ES module scope 8.615 at file:///app/node_modules/.vite-temp/vite.config.ts.timestamp-1744012997583-aad75c07ea95a.mjs:34:1 8.615 at ModuleJob.run (node:internal/modules/esm/module_job:193:25) 8.615 at async Promise.all (index 0) 8.615 at async ESMLoader.import (node:internal/modules/esm/loader:530:24) 8.615 at async loadConfigFromBundledFile (file:///app/node_modules/vite/dist/node/chunks/dep-B0fRCRkQ.js:54640:15) 8.615 at async bundleAndLoadConfigFile (file:///app/node_modules/vite/dist/node/chunks/dep-B0fRCRkQ.js:54483:22) 8.615 at async loadConfigFromFile (file:///app/node_modules/vite/dist/node/chunks/dep-B0fRCRkQ.js:54445:44) 8.615 at async resolveConfig (file:///app/node_modules/vite/dist/node/chunks/dep-B0fRCRkQ.js:53944:24) 8.615 at async createBuilder (file:///app/node_modules/vite/dist/node/chunks/dep-B0fRCRkQ.js:51949:18) 8.615 at async CAC.<anonymous> (file:///app/node_modules/vite/dist/node/cli.js:859:23) ------ failed to solve: process "/bin/sh -c npm run build" did not complete successfully: exit code: 1
04-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值