以何为家
以何为家
  • 发布:2021-11-04 11:25
  • 更新:2024-11-09 02:35
  • 阅读:6357

Module build failed (from ./node_modules/@dcloudio/webpack-uni-mp-loader/lib/script.js):

分类:uni-app

Module build failed (from ./node_modules/@dcloudio/webpack-uni-mp-loader/lib/script.js):
万万没想到,报错是因为//#ifdef 条件编译出了问题,除了//#ifdef 和 //endif没有成对出现外,还有什么//#ifdef 之后有其他文本,//#ifdef之后有注释文本,具体见下文:
第一行 Module build failed 报错内容是一样的,具体区别注意第二行之后的。
1、没有成对出现:

            //条件编译报错测试  
            test(){  
                //#ifdef MP-WEIXIN  
                uni.showToast({  
                    title:"测试代码",  
                    icon:"none"  
                })  

            },

区别:Error: Unbalanced delimiter found in string
这句翻译下是说“在字符串中找到不平衡的分隔符”,基本猜猜也能找到错误。

 Module build failed (from ./node_modules/@dcloudio/webpack-uni-mp-loader/lib/script.js):  
 Error: Unbalanced delimiter found in string  
     at Function.XRegExp.matchRecursive (F:\HbuilderX\HBuilderX.3.2.9.20210927.full\HBuilderX\plugins\uniapp-cli\node_modules\xregexp\lib\addons\matchrecursive.js:186:23)  
     at matchReplacePass (F:\HbuilderX\HBuilderX.3.2.9.20210927.full\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\packages\webpack-preprocess-loader\preprocess\lib\preprocess.js:303:27)  
     at replaceRecursive (F:\HbuilderX\HBuilderX.3.2.9.20210927.full\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\packages\webpack-preprocess-loader\preprocess\lib\preprocess.js:333:10)  
     at preprocessor (F:\HbuilderX\HBuilderX.3.2.9.20210927.full\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\packages\webpack-preprocess-loader\preprocess\lib\preprocess.js:168:10)

2、//#ifdef 后面有文本

            //条件编译报错测试  
            test(){  
                //#ifdef MP-WEIXIN 小程序执行  
                uni.showToast({  
                    title:"测试代码",  
                    icon:"none"  
                })  
                //#endif  
            },

区别:SyntaxError: Unexpected identifier
这里翻译下说是“意外的标识符”,当时顺手在后面加了个注释,一直报错,差点重装,是挺意外的,编译器要是报个错在哪一行也还好啊。。。

 Module build failed (from ./node_modules/@dcloudio/webpack-uni-mp-loader/lib/script.js):  
 SyntaxError: Unexpected identifier  
     at new Function (<anonymous>)  
     at getTestTemplate (F:\HbuilderX\HBuilderX.3.2.9.20210927.full\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\packages\webpack-preprocess-loader\preprocess\lib\preprocess.js:375:10)  
     at testPasses (F:\HbuilderX\HBuilderX.3.2.9.20210927.full\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\packages\webpack-preprocess-loader\preprocess\lib\preprocess.js:379:16)

3、//#ifdef 后面有注释

            //条件编译报错测试  
            test(){  
                //#ifdef MP-WEIXIN //小程序执行  
                uni.showToast({  
                    title:"测试代码",  
                    icon:"none"  
                })  
                //#endif  
            },

区别:SyntaxError: Unexpected token '}'
习惯在代码后面紧接着写注释的要小心了,//#ifdef 后前外别写。给你报个“}”的错,这下你去找“{ }”吧,越找越迷茫。

 Module build failed (from ./node_modules/@dcloudio/webpack-uni-mp-loader/lib/script.js):  
 SyntaxError: Unexpected token '}'  
     at new Function (<anonymous>)  
     at getTestTemplate (F:\HbuilderX\HBuilderX.3.2.9.20210927.full\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\packages\webpack-preprocess-loader\preprocess\lib\preprocess.js:375:10)  
     at testPasses (F:\HbuilderX\HBuilderX.3.2.9.20210927.full\HBuilderX\plugins\uniapp-cli\node
0 关注 分享

要回复文章请先登录注册

1***@163.com

1***@163.com

根据你说的第二点解决了问题,谢谢!
2024-11-09 02:35