'Publish Typescript Interfaces with NPM

I'm working in a project that has multiple typescript projects. I'm trying to have a common package for all the interfaces, types, enums, etc.

I thought I could make it work creating a NPM package with Typescript and have an index.ts with this content:

index.ts content

When I'm working in the projects that depend on this package, everything seems fine, but when I want to start the development environment I'm getting this error:

Error with ts-node/register

I've got the suggestion of running ts-node with --skipIgnore flag, but I'm getting the same error:

Error with skipIgnore

Maybe I needed to compile the code and import the .js (doesn't make ANY sense, but at this point 🤷🏽‍♂️)... no luck.

Let me share both tsconfig.json:

The one from the "common" package:

tsconfig from common package

The one from the project that depends on the common package:

tsconfig from dependant project


Things suggested and tried:

Because your target is ES6, commonjs modules cannot use your package. The dependent project should change its module type to ES6 as well - @kellys

Changing project's module to ES6, brings me this error: Error with ES6

All right, let's add moduleResolution: "node" ... and I'm getting: Error with moduleResolution:node

So I'm adding "type":"module" in package.json: Error with type module in package json



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source