Uncaught ReferenceError: require is not defined (javascript)
Uncaught ReferenceError: require is not defined (javascript)
所以,我正在尝试将节点模块与 JavaScript 一起使用,为此,我需要使用 "require" 加载模块,所以我安装了 Require.js,如下所示:
npm i requirejs
这是我的代码:
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");
但是,我总是得到这个错误:
require is not defined
我试过 Browserify 并解决了问题,但我需要另一个没有 Browserify 的解决方案。有什么想法吗?
这对你有帮助:
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 ✔
http://requirejs.org/docs/download.html
将此添加到您的项目中:download_me
请通过 require.js docs.
所以,我正在尝试将节点模块与 JavaScript 一起使用,为此,我需要使用 "require" 加载模块,所以我安装了 Require.js,如下所示:
npm i requirejs
这是我的代码:
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");
但是,我总是得到这个错误:
require is not defined
我试过 Browserify 并解决了问题,但我需要另一个没有 Browserify 的解决方案。有什么想法吗?
这对你有帮助:
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 ✔
http://requirejs.org/docs/download.html
将此添加到您的项目中:download_me
请通过 require.js docs.