2015-03-08 184 views
1

我有一個使用npm和節點的舊mac上的項目。當我更換計算機時,我將該文件複製到新的mac中,然後運行npm install,然後嘗試運行帶有browserify的腳本,該代碼將轉儲ES6的代碼。我不斷收到錯誤錯誤:無法找到模塊'./args'

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" {} \; 
0123的輸出

注意,基於下面的輸出,我做npm iwatchifyrequirekarma,但錯誤消息仍然

./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

在您的項目中搜索require('./ args')或require(「./ args」),是否有任何調用? – 2015-03-08 18:31:44

+0

@YuriZarubin在Mac上,我試過這個'find。 -type f -name「require('./ args')」'在項目目錄中,沒有結果 – Leahcim 2015-03-08 21:24:55

+0

'find。 -name \ *。js -exec grep -H「\ ./ args」{} \;'是你可能想要的。 – avandeursen 2015-03-09 13:27:27

回答

6

@avandeursen建議我運行此命令

find . -name \*.js -exec grep -H "\./args" {} \; 

定位在項目中需要('/ args')代碼,並根據OP更新中的輸出,我重新安裝browserify npm i browserify,現在錯誤消息已消失。

+3

我將我的'node_modules'文件夾複製到不同的項目後遇到了這個問題。與你的解決方案類似,殺死'node_modules'併爲我重新安裝。 – L1fescape 2016-05-07 23:02:51