[英]How can I import an npm module from a parent directory?
Given the following project structure:鉴于以下项目结构:
- parentPrj
- prj1
- node_modules
- package.json
- index.js
- prj2
- node_modules
- package.json
- node_modules
- react
- react.js
- package.json
Is it possible to import inside the sources of prj1 the dependencies from node_modules
of the parent?是否可以在 prj1 的源中导入来自父节点的 node_modules 的依赖
node_modules
? If yes - how?如果是 - 如何? Currently it gives an error
Unable to resolve module
目前它给出了一个错误
Unable to resolve module
In this concrete example, how can I import react.js
from index.js
在这个具体的例子中,我如何从
index.js
导入react.js
如果您不想使用lerna (已在其中一条评论中提到),最简单的解决方案可能是创建从项目 A 的node_modules
文件夹到父文件夹的符号链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.