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 in shared_ponent_lib. And does index.js exist in the root of your application. Usually should be in lib/index.js or src/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 run npm link in shared_ponent_lib and npm 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
Add a ment  | 

1 Answer 1

Reset to default 6

You 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