微信小程序 “require is not defined” require报错
问题描述
import等正常,文件引用出现问题
(这里的路径没错)
甚至存储require结果的变量不完全为空
displayDetail = require("./states/forbid");
console.log(displayDetail.rightColor);
console.log(displayDetail.rightIcon);
解决办法
感谢大佬的提示,总结为不看文档
完整文件:
{
"cloudfunctionRoot": "cloudfunctions/",
"description": "项目配置文件",
"packOptions": {
"ignore": [],
"include": []
},
"miniprogramRoot": "miniprogram/",
"compileType": "miniprogram",
"setting": {
"packNpmManually": true,
"packNpmRelationList": [
{
"packageJsonPath": "./package.json",
"miniprogramNpmDistDir": "./miniprogram"
}
],
"useCompilerPlugins": [
"typescript"
],
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"minifyWXSS": true,
"minifyWXML": true,
"es6": true,
"enhance": true,
"postcss": true,
"minified": false,
"condition": false,
//============这里新增==========================
"ignoreUploadUnusedFiles": false,
"ignoreDevUnusedFiles": false,
"ignoreDevUnusedFile": false
//================================================
},
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {},
"srcMiniprogramRoot": "miniprogram/",
"appid": "wxbf940e4130bd8d1e",
"libVersion": "2.28.1",
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
},
"checkSiteMap": false,
"cloudfunctionTemplateRoot": "cloudfunctionTemplate/"
}
解决思路
既然console都没出现问题,那么必然是微信的问题了
根本没能力判断哪些文件是无用依赖
点到为止.jpg
配置环境
语言:Typescript
文件结构:
所以是组件引用外部文件的问题,不知道算不算微信的bug
project.config.json位置在根目录: