未捕获的 ReferenceError: require 未定义 (javascript)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50426233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 09:06:08  来源:igfitidea点击:

Uncaught ReferenceError: require is not defined (javascript)

javascriptnode.jsrequire

提问by Az Emna

So, I'm trying to use node modules with JavaScript and for that, I need to load the modules with "require", so I installed Require.js like so:

所以,我试图在 JavaScript 中使用节点模块,为此,我需要使用“require”加载模块,所以我像这样安装了 Require.js:

npm i requirejs

This is my code:

这是我的代码:

var ecurve = require('ecurve') ;
var BigInteger = require('bigi')
var AES = require("crypto-js/aes");
var SHA256 = require("crypto-js/sha256");
var CryptoJS = require("crypto-js");

However, I always get this error:

但是,我总是收到此错误:

require is not defined 

I've tried Browserify and solved the problem but I need another solution without Browserify. Any ideas?

我已经尝试过 Browserify 并解决了这个问题,但我需要另一个没有 Browserify 的解决方案。有任何想法吗?

采纳答案by Harvey

This would help you:

这将帮助您:

RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node. Using a modular script loader like RequireJS will improve the speed and quality of your code.

IE 6+ .......... compatible ?
Firefox 2+ ..... compatible ?
Safari 3.2+ .... compatible ?
Chrome 3+ ...... compatible ?
Opera 10+ ...... compatible ?

RequireJS 是一个 JavaScript 文件和模块加载器。它针对浏览器中的使用进行了优化,但也可以在其他 JavaScript 环境中使用,例如 Rhino 和 Node.js。使用像 RequireJS 这样的模块化脚本加载器将提高代码的速度和质量。

IE 6+ .......... compatible ?
Firefox 2+ ..... compatible ?
Safari 3.2+ .... compatible ?
Chrome 3+ ...... compatible ?
Opera 10+ ...... compatible ?

http://requirejs.org/docs/download.html

http://requirejs.org/docs/download.html

Add this to your project: download_me

将此添加到您的项目中:download_me

please go through require.js docs.

请阅读require.js 文档