0

I have published a npm package called sum . which have just main.js file:

export function sum (a , b){ return a+b } 

My package.json is like this :

{ "name":"sum", "version":"1.0.0", "description":"simple npm package", "main":"./main.js", "module":"./main.js" } 

I installed it in another directory and import it:

import {sum} from "sum" alert(sum(1,2)) 

but it gave this error:

Uncaught TypeError: Failed to resolve module specifier "sum". Relative references must start with either "/", "./", or "../". 

1 Answer 1

1

locally you need to spacify the path of the module main.js file on importing

like this

import {sum} from '/path/to/direc/main.js' 

or

you can add the package in your local npm modules and test.

for this you have to run.

cd ~/projects/your-pkg # go into the package directory npm link # creates global link cd ~/projects/curr_proj # go into some other package directory. npm link package name # link-install the package 
Sign up to request clarification or add additional context in comments.

1 Comment

yes , I know but I am telling you that I have published the sum package and installed it with npm install sum

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.