2016-03-02 53 views
0

環境: [email protected] [email protected] [email protected] [email protected]Browserify - 變換的package.json的符號鏈接模塊npm3不工作

試圖構建與[email protected]工作的應用程序和[email protected],但在升級到[email protected][email protected]時出現問題。請允許我嘗試解釋問題。

  • app/node_modules我已經通過通過npm link符號鏈接npm install和本地模塊安裝的模塊。

  • 本地模塊已在其package.json如指定browserify變換 -

}, "devDependencies": { "babel-preset-es2015": "^6.5.0", "babelify": "^7.2.0" }, "browserify": { "transform": [ [ "babelify", { "presets": [ "es2015" ] } ] ] }

試圖建立我得到錯誤:

"Browserify Error: Couldn't find preset "es2015" relative to directory"

NPM 3已經夷爲平地依賴樹,所以babel-preset-es2015的yinkinked模塊需要位於appnode_modules。根據@substack here的解釋和這個例子here browserify應該從符號鏈接模塊走到樹上app並在那裏檢查node_modules,但是它似乎沒有這樣做。

我的目錄結構是這樣的:

~/projects |-- app |-- entry.js (this file can see babel-preset just fine) |-- node_modules |-- babel-preset-es2015 |-- my-module (symlink pointing at ~/projects/modules-shared/my-module) |-- index.js (we want babelify to transform this file) |-- modules-shared |-- my-module

如果我在modules-shared文件夾中安裝babel-preset-es2015,browserify找到預設。

+0

你有沒有解決你的問題? – Shawn

回答

1

回到這個問題,我有點忽略。這個問題很難解決,因爲它涉及到所用工具的兩個不同特徵。

首先,Browserify不會像它應該那樣處理符號鏈接。它不是將符號鏈接的npm模塊視爲其符號鏈接位置,而是將其實際位置置於文件系統中,因此無法在npm3的扁平文件樹下找到它的依賴關係。其次,Babel要求其依賴關係位於所討論模塊的node_modules中,這實際上是對npm2嵌套文件樹系統的一種強烈依賴。

因此,出於同樣的原因,我們有兩個不同的問題--npm3改變了node_modules的組織方式。

我能找到的最佳解決方法是編寫一個只安裝任何符號鏈接模塊的babel依賴項的自定義腳本。您可能認爲只安裝符號鏈接模塊的所有依賴關係是一個好主意,但這會導致Browserified bundle中的重複實例,從而導致各種微妙的,難以理解的錯誤。

可以用這個變換realpathify來解決Browserify問題,但對於Babel的問題,我沒有看到任何解決方案的動向。

相關問題