我的旧Mac上有一个使用npm和node的项目。当我更换计算机时,我将文件复制到新的mac中,并运行npm install
,然后尝试使用browserify运行脚本,该脚本将转换ES6的代码。我一直收到错误
Error: Cannot find module './args'
我认为它不是一个模块。我也试图单独重新安装主要模块,但错误仍在继续。问题:当它说“找不到模块'./args'时,它是什么意思?我该如何解决这个错误?
"scripts": {
"build-js": "browserify app/app.js app/goopy.js app/models.js app/goofy.js -t babelify > app/bundle.js"
},
的package.json
"devDependencies": {
"babelify": "^5.0.3",
"bower": "^1.3.1",
"http-server": "^0.6.1",
"karma": "^0.12.31",
"karma-junit-reporter": "^0.2.2",
"protractor": "^1.1.1",
"shelljs": "^0.2.6",
"browserify": "latest",
"watchify": "latest",
"gulp": "latest",
"vinyl-source-stream": "latest",
"karma-phantomjs-launcher": "^0.1.4",
"karma-qunit": "^0.1.4"
},
"dependencies": {
"JSON2": "^0.1.0",
"grunt": "^0.4.5",
"grunt-contrib-watch": "^0.6.1",
"gulp": "^3.8.11",
"karma": "0.12.31",
"qunit": "0.7.5",
"requirejs": "^2.1.16",
"sinon": "^1.12.2",
"watchify": "^2.4.0"
}
这是完整的错误消息
Error: Cannot find module './args'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/mm/sites/backbone-seed/node_modules/.bin/browserify:6:9)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
更新 以下是正在运行的输出
find . -name \*.js -exec grep -H "\./args" {} \;
注意,根据下面的输出,我对npm i
,watchify
和require
进行了karma
,但错误消息仍为
./node_modules/browserify/bin/cmd.js:var b = require('./args')(process.argv.slice(2));
grep: ./node_modules/browserify/node_modules/crypto-browserify/node_modules/browserify-sign/node_modules/bn.js: Is a directory
grep: ./node_modules/browserify/node_modules/crypto-browserify/node_modules/browserify-sign/node_modules/elliptic/node_modules/hash.js: Is a directory
grep: ./node_modules/browserify/node_modules/crypto-browserify/node_modules/browserify-sign/node_modules/parse-asn1/node_modules/asn1.js: Is a directory
grep: ./node_modules/browserify/node_modules/crypto-browserify/node_modules/create-ecdh/node_modules/bn.js: Is a directory
grep: ./node_modules/browserify/node_modules/crypto-browserify/node_modules/create-ecdh/node_modules/elliptic/node_modules/hash.js: Is a directory
grep: ./node_modules/browserify/node_modules/crypto-browserify/node_modules/create-hash/node_modules/sha.js: Is a directory
grep: ./node_modules/browserify/node_modules/crypto-browserify/node_modules/diffie-hellman/node_modules/bn.js: Is a directory
grep: ./node_modules/browserify/node_modules/crypto-browserify/node_modules/public-encrypt/node_modules/bn.js: Is a directory
grep: ./node_modules/browserify/node_modules/crypto-browserify/node_modules/public-encrypt/node_modules/parse-asn1/node_modules/asn1.js: Is a directory
grep: ./node_modules/browserify/node_modules/shasum/node_modules/sha.js: Is a directory
./node_modules/karma/node_modules/http-proxy/node_modules/utile/lib/index.js: return utile.args = require('./args');
./node_modules/watchify/bin/cmd.js:var fromArgs = require('./args.js');
./node_modules/watchify/node_modules/browserify/bin/cmd.js:var b = require('./args')(process.argv.slice(2));
grep: ./node_modules/watchify/node_modules/browserify/node_modules/crypto-browserify/node_modules/browserify-sign/node_modules/bn.js: Is a directory
grep: ./node_modules/watchify/node_modules/browserify/node_modules/crypto-browserify/node_modules/browserify-sign/node_modules/elliptic/node_modules/hash.js: Is a directory
grep: ./node_modules/watchify/node_modules/browserify/node_modules/crypto-browserify/node_modules/browserify-sign/node_modules/parse-asn1/node_modules/asn1.js: Is a directory
grep: ./node_modules/watchify/node_modules/browserify/node_modules/crypto-browserify/node_modules/create-ecdh/node_modules/bn.js: Is a directory
grep: ./node_modules/watchify/node_modules/browserify/node_modules/crypto-browserify/node_modules/create-ecdh/node_modules/elliptic/node_modules/hash.js: Is a directory
grep: ./node_modules/watchify/node_modules/browserify/node_modules/crypto-browserify/node_modules/create-hash/node_modules/sha.js: Is a directory
grep: ./node_modules/watchify/node_modules/browserify/node_modules/crypto-browserify/node_modules/diffie-hellman/node_modules/bn.js: Is a directory
grep: ./node_modules/watchify/node_modules/browserify/node_modules/crypto-browserify/node_modules/public-encrypt/node_modules/bn.js: Is a directory
grep: ./node_modules/watchify/node_modules/browserify/node_modules/crypto-browserify/node_modules/public-encrypt/node_modules/parse-asn1/node_modules/asn1.js: Is a directory
grep: ./node_modules/watchify/node_modules/browserify/node_modules/shasum/node_modules/sha.js: Is a directory
答案 0 :(得分:6)
@avandeursen建议我运行这个命令
find . -name \*.js -exec grep -H "\./args" {} \;
在项目中找到require(&#39; / args&#39;)代码,并根据OP更新中的输出,重新安装browserify npm i browserify
,现在错误消息消失了
答案 1 :(得分:1)
复制项目时,最好从全新安装开始进行依赖:
删除目录
/node_modules/
输入您的终端
npm install
运行代码