Can't resolve module after npm-link for shared component repository

Viewed 5597

It is my first time trying npm-link, trying to create a shared component 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_component_lib

The module is showing fine the the node_modules folder, however, when I try to add the component 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_component_lib i have:

  "name": "@linked/project",
  "version": "0.1.0",
  "main": "index.js",
  "dependencies": {
   ...
  },

I am exporting the component 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.

1 Answers

You should edit the package.json in shared_component_lib from "main": "index.js" to the actual location of file

ex:- "main" : "lib/index.js" or "main": "src/index.js"

Related