微信小程序 “require is not defined” require报错

这篇具有很好参考价值的文章主要介绍了微信小程序 “require is not defined” require报错。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

微信小程序 “require is not defined” require报错

问题描述

import等正常,文件引用出现问题
小程序require报错,微信小程序,小程序,typescript
(这里的路径没错)

甚至存储require结果的变量不完全为空

		displayDetail = require("./states/forbid");
      	console.log(displayDetail.rightColor);
      	console.log(displayDetail.rightIcon);

小程序require报错,微信小程序,小程序,typescript

解决办法

微信小程序require报错

感谢大佬的提示,总结为不看文档
小程序require报错,微信小程序,小程序,typescript
完整文件:

{
  "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
文件结构:
小程序require报错,微信小程序,小程序,typescript
所以是组件引用外部文件的问题,不知道算不算微信的bug
project.config.json位置在根目录:
小程序require报错,微信小程序,小程序,typescript文章来源地址https://www.toymoban.com/news/detail-737933.html

到了这里,关于微信小程序 “require is not defined” require报错的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 微信小程序错误----config is not defined

    微信小程序出错  请求头发生错误 修改  

    2024年02月22日
    浏览(36)
  • vue3 使用require报错:require is not defined

    1.报错原因 vue3使用vite打包 里面没有require方法, webpack 里面有这个方法 2.解决方案 使用import 代替 *注: 资源可使用import.meta.globEager(“…/*.png”) ; 动态引入,需要给 css 路径加括号 vite官网静态资源处理 new URL(url, import.meta.url) import.meta.url : ESM 的原生功能,会暴露当前模块的

    2024年02月07日
    浏览(35)
  • 解决浏览器 require is not defined 的报错问题

    在node环境中引入了一些包,用webpack打包后放在浏览器环境中,浏览器报错 require is not defined 。 这是因为 require 是node环境下的CommonJs,而 import 是浏览器环境下的ESModule。ESModule不认识require。 require 是node的一个私有的全局方法。 那就让打包出来的代码别有require,换句话说,

    2024年02月15日
    浏览(40)
  • 微信小程序module “utils/util.js“ is not defined

    有一次我把小程序的index文件删除后报错了。 报错:module “utils/util.js” is not defined 微信小程序Error: module “utils/util.jsx.js” is not defined 在网上找了半天没发现解决方案。 解决方案:把开发工具关闭,然后重新打开就好了

    2024年02月16日
    浏览(36)
  • 微信小程序 Error: module ‘xxx.js‘ is not defined

    可能是两种问题出现的报错 一种是因为es6转es5没有开启 还有一种可能是因为导入的js文件过大,自动跳过了es6转es5的处理 推荐一个压缩js的网址:https://babeljs.io/repl

    2024年02月12日
    浏览(40)
  • node.js报错 ReferenceError require is not defined 解决方案

    从node.js 14版及以上版本中,require作为COMMONJS的一个命令已不再直接支持使用,所以我们需要导入createRequire命令才可以; 在使用 require 的地方需要加入以下代码:

    2024年01月18日
    浏览(45)
  • Error: module ‘pages下某.js‘ is not defined 微信小程序

    解决问题: 【1】In strict mode code, functions can only be declared at top level or inside a block解决微信小程序中pages下某js文件is not defined问题 【2】解决微信小程序中pages下某js文件is not defined问题 报错结果如下:  问题代码:  问题在于在此代码外没有Page({ }),导致了严格模式下出现错

    2024年02月13日
    浏览(27)
  • 解决报错: require is not defined in ES module scope

    用node启动mjs文件报错:require is not defined in ES module scope 现象如下:  原因: 文件后缀是mjs, 被识别为es模块,但是node默认是commonjs格式,不支持也不能识别es模块。 解决办法:把文件后缀从.mjs改成 ==》.cjs后缀 补充资料: .cjs 代表使用 CommonJS 模块 .mjs 代表使用 ES 模块 首先我

    2024年02月08日
    浏览(43)
  • ReferenceError: require is not defined 【vue3 +vite +setup语法使用报错】

    原本我们在vue2时代,可以使用require 导入静态资源,如下所示 但在vue3中的vite没有require方法定义的使用,说白了就是不使用require方法进行资源的导入,而是使用新的方法。详情请看官网。 Vite官网 我这里提供两种方法: 方法1: 使用 import导入资源 方法2: 直接使用 new URL(

    2024年02月13日
    浏览(32)
  • 微信小程序报页面【pages/books/books]错误: ReferenceError: app is not defined的解决

    微信小程序实现点击图标跳转打开文档(文档在nginx反向代理服务器上),编译时报错 检查发现是因为我把内网穿透地址写在app.js当中  在该page的js文件中用到该地址之前应该先对app赋值(说法不准确),不然它怎么知道这个app是神马东西。 即 然后问题解决   (突然疑惑为

    2024年02月11日
    浏览(40)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包