admin管理员组文章数量:1327661
It is my first time trying npm-link, trying to create a shared ponent repository, and have hit an issue. I think I have linked the projecteds correctly as this message is displayed:
/Users/tom.allen/Development/main/project/node_modules/@linked/project -> /usr/local/lib/node_modules/@linked/project -> /Users/tom.allen/Development/shared_ponent_lib
The module is showing fine the the node_modules folder, however, when I try to add the ponent I created in the @linked/test repository I get an error saying:
Module not found: Error: Can't resolve '@linked/project' in '/Users/tom.allen/Development/...'
In the package.json for shared_ponent_lib i have:
"name": "@linked/project",
"version": "0.1.0",
"main": "index.js",
"dependencies": {
...
},
I am exporting the ponent as:
export { default as Hello } from './Hello';
and importing as:
import {Hello } from '@linked/project';
I have triple checked for spelling mistakes and had a look over the webpack config (which is far from a strong point for me) but can't really see where i've gone wrong.
Apologies in advance if this doesn't make much sense! Any help will be massively appreciated.
It is my first time trying npm-link, trying to create a shared ponent repository, and have hit an issue. I think I have linked the projecteds correctly as this message is displayed:
/Users/tom.allen/Development/main/project/node_modules/@linked/project -> /usr/local/lib/node_modules/@linked/project -> /Users/tom.allen/Development/shared_ponent_lib
The module is showing fine the the node_modules folder, however, when I try to add the ponent I created in the @linked/test repository I get an error saying:
Module not found: Error: Can't resolve '@linked/project' in '/Users/tom.allen/Development/...'
In the package.json for shared_ponent_lib i have:
"name": "@linked/project",
"version": "0.1.0",
"main": "index.js",
"dependencies": {
...
},
I am exporting the ponent as:
export { default as Hello } from './Hello';
and importing as:
import {Hello } from '@linked/project';
I have triple checked for spelling mistakes and had a look over the webpack config (which is far from a strong point for me) but can't really see where i've gone wrong.
Apologies in advance if this doesn't make much sense! Any help will be massively appreciated.
Share Improve this question edited Oct 22, 2019 at 12:39 Thomas Allen asked Oct 22, 2019 at 11:11 Thomas AllenThomas Allen 8118 gold badges18 silver badges33 bronze badges 5-
Did you see any errors while executing
npm link
inshared_ponent_lib
. And doesindex.js
exist in the root of your application. Usually should be inlib/index.js
orsrc/index.js
– Nithin Thampi Commented Oct 22, 2019 at 12:41 - Hi @nithin There weren't any errors when executing npm link. Index.js is in the src folder, so src/index.js. – Thomas Allen Commented Oct 22, 2019 at 12:45
-
Can you update
shared_ponent_lib
package.json to"main": "src/index.js"
and then runnpm link
inshared_ponent_lib
andnpm link @shared/project
in main project. – Nithin Thampi Commented Oct 22, 2019 at 12:46 - Let me know the results after you do the same. I'm suspecting this error will go away but another error should pop up :) – Nithin Thampi Commented Oct 22, 2019 at 12:54
- That did it! Thank you! – Thomas Allen Commented Oct 23, 2019 at 11:04
1 Answer
Reset to default 6You should edit the package.json in shared_ponent_lib
from "main": "index.js"
to the actual location of file
ex:- "main" : "lib/index.js"
or "main": "src/index.js"
本文标签: javascriptCan39t resolve module after npmlink for shared component repositoryStack Overflow
版权声明:本文标题:javascript - Can't resolve module after npm-link for shared component repository - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742226961a2436500.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论