0

I am developing a very simple npm package (type-exception) with TypeScript. My tests runs without errors and I was able to publish on NPM and even I can install it in another project (project B); but when I import it as reference, VS Code throw me an Exception "cannot find 'type-exception' module" (on project B)

I have installed another package on project B without errores, so I think my package that I released on NPM has some issue, but I cannot figure what is.

Basically, I made two classes and in the main.ts file export them like this:

export { nameof } from "./reflection-helper";
export { TypeException } from "./type-exception";

My folder project structure of type-exception project is like this:

src
+-src
|--index.ts
|--reflection-helper.ts
|--type-exception.ts
|-test
|-node_modules
+-lib
|--src
|--test

The source code of "type-exception" project can be found here

1 Answer 1

2

throw me an Exception "cannot find 'type-exception' module" (on project B)

This is a runtime exception. This is because your project's main is not pointing a file : https://github.com/vvenegasv/type-exception/blob/f7ec4f63a4cb129e73ed2c4592014adb7b363913/src/package.json#L5

It is

"main": "type-exception",

Should be like

"main": "./lib/something/type-exception",
Sign up to request clarification or add additional context in comments.

2 Comments

Need I to put the file extension? Like this? "main": "./lib/src/type-exception.js"
Ok, I fix it changing this line to "main": "./src/index.ts". Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.