2017-04-17 32 views
0

我想使用保存在父目錄中的共享節點模塊。我有以下文件夾結構:如何讓webpack使用父目錄中的共享節點模塊

  • 父目錄
    • node_modules
    • 公司
      • serverless.yml
      • handler.js
      • webpack.config

我必須使用webpack創建包並上傳到aws-lamda。但是webpack正在尋找節點模塊。但我收到以下錯誤:

Overriding the webpack directory in serverless-webpack since it uses v1 version of webpack... 
cp: cannot stat 'node_modules/webpack': No such file or directory 

如何使webpack.config指向父目錄中的node_modules?

+0

你運行了嗎? ned npm安裝沒有發生任何錯誤? – Gntem

+0

我想使用在父目錄中的共享節點模塊 – suku

+0

這看起來不像webpack錯誤,但像shell腳本錯誤,您嘗試「cp」一個不存在的文件。如果沒有在當前目錄的node_modules中找到它,webpack會很高興地查看父節點'node_modules',除非另有配置。你能告訴我們你正在運行的腳本嗎? –

回答

0

如果您閱讀了NodeJS require文檔,強烈建議您使用本地node_modules文件夾,即使您的軟件包需要具有相同的依賴關係。

https://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders

或者你可以用NODE_PATH工作,需要首先考慮本地node_modules通知,然後開始尋找到其他文件夾,以便嘗試刪除本地node_modules

If the NODE_PATH environment variable is set to a colon-delimited list of absolute paths, then Node.js will search those paths for modules if they are not found elsewhere. (Note: On Windows, NODE_PATH is delimited by semicolons instead of colons.)

由於的WebPack暴露出許多模塊解析選項https://webpack.github.io/docs/resolving.html

Resolving a module path For resolving a module Resolve first gathers all search directories for modules from Webpack’s context directory. This process is similar to the node.js resolving process, but the search directories are configurable with the configuration option resolve.modulesDirectories. In addition to this the directories in the configuration option resolve.root are prepended, and directories in the configuration option resolve.fallback are appended.