2016-02-17 59 views
3

我使用帶有Gulp系統的Browserify構建器,從reactify JSX編譯器移動到Babel編譯器(Babelify)。 現在,我得到這個錯誤:Babelify錯誤找不到模塊'lodash/array/compact'

[00:17:25] Error in bundle: 
[00:17:25] Error: Cannot find module 'lodash/array/compact' while parsing file: 
C:\MotoGipsy\repository\motogipsy\client-trunk\public\src\scripts\app.js 
    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> (C:\MotoGipsy\repository\motogipsy\client-trunk\node_m 
odules\babel-preset-es2015\node_modules\babel-plugin-transform-es2015-function-n 
ame\node_modules\babel-types\lib\index.js:42:27) 
    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 Module.require (module.js:365:17) 
    at require (module.js:384:17) 

我使用的是咕嘟咕嘟配置:

var browserify = require('browserify'), 
    babelify = require('babelify'); 

module.exports = function(config){ 
    // Create a browserify instance with proper options 
    var bundler = browserify({ 
     cache: {}, packageCache: {}, fullPaths: true, 
     debug: config.browserify.debug, 
     paths: config.browserify.paths 
    }) 
    .transform(babelify, {presets: ["es2015", "react"]}); 

    // Add the entry module to the bundler 
    bundler.add('./public/src/scripts/app.js'); 

    return bundler; 
}; 

這是的package.json配置:

"dependencies": { 
    "babel": "^6.5.2", 
    "marked": "0.3.5", 
    "es5-shim": "^4.0.5", 
    "extend": "^2.0.0", 
    "gulp": "^3.8.10", 
    "gulp-autoprefixer": "^2.0.0", 
    "gulp-concat": "^2.4.2", 
    "gulp-cssmin": "^0.1.6", 
    "gulp-sass": "^1.2.4", 
    "gulp-shell": "^0.2.11", 
    "gulp-sourcemaps": "^1.3.0", 
    "gulp-uglify": "^1.5.2", 
    "gulp-util": "^3.0.1", 
    "gulp-watch": "^3.0.0", 
    "jquery": "^2.2.0", 
    "react": "^0.14.7", 
    "react-router": "2.0.0", 
    "reflux": ">=0.3.0", 
    "watchify": "^2.2.1", 
    "browserify-shim": "~3.8.9", 
    "react-textarea-autosize": "3.3.0", 
    "react-autolink-text": "2.0.0", 
    "core-js": "2.1.0" 
    }, 
    "devDependencies": { 
    "babel-preset-es2015": "^6.5.0", 
    "babel-preset-react": "^6.5.0", 
    "babelify": "^7.2.0", 
    "jest": "^0.1.37", 
    "jest-cli": "^0.2.1", 
    "lodash": "^4.5.0" 
    }, 

我真搞不清楚這個情況。請讓我知道爲什麼這種依賴不會與Babel插件一起使用?我怎樣才能解決這個問題?

+0

我遇到同樣的問題,但運行Frisby測試框架。你有這個固定的嗎?由於其他解決方案不適合我。 – Edvinauskas

回答

0

就我而言,原因是過時的NPM。所以:

$ sudo npm install -g npm 

解決了我的問題。

不只是運行npm install再次重裝依賴

0

我也遇到過類似的問題。在我的一file文件中,它的使用類似於

var compact = require('lodash/array/compact') 
compact(assetTasks.map(matchFilter)) 

但是使用新的lodash,您不能像以前那樣使用緊湊模塊。所以下面解決了我的問題。

var array = require('lodash/array') 
array.compact(assetTasks.map(matchFilter))