I just created my first JavaScript library (ana.js), I used TypeScript and compiled everything from ~/src/ts/index.ts into the dist directory. This are the compiler options of the library:
{
"target": "es2016",
"lib": ["es2017", "dom", "DOM.Iterable"],
"module": "ES6",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"declaration": true
}
Then I created a sample project to test that I published correctly the library. I scaffolded a Vite project and installed the ana.js package. Then, I imported the library in the main.ts file:
import { Ana } from 'ana.js'
console.log(Ana)
When running the Vite server, it throws of missing declarations and references. Uncaught ReferenceError: exports is not defined I think this means I built the library using a wrong module, but I'm not really sure. Any help is welcome. Thank you.