I published a library user-credits on npm, but I'm unable to access it from my other projects.
When accessing it locally, pointing to the folder as follows:
package.json
{
"name": "user-credits-test",
"version": "1.0.0",
"description": "Testing user-credits library",
"scripts": {
"build": "tsc",
"test": "node ./dist/test.js"
},
"type": "module",
"dependencies": {
"user-credits": "../../UserCredits"
},
"devDependencies": {
"typescript": "^5.2.2"
}
}
And this tsconfig.js:
{
"compilerOptions": {
"moduleResolution": "node",
"target": "ESNext",
"module": "ESNext",
"outDir": "dist",
"rootDir": "src",
"baseUrl": ".",
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "dist"]
}
It compiles and runs with no problem!
But when I publish that exact directory to npm and import it from as a remote dependency ("user-credits": "0.9.4-alpha")
:
package.json
{
"name": "user-credits-test",
"version": "1.0.0",
"description": "Testing user-credits library",
"scripts": {
"build": "tsc",
"test": "node ./dist/test.js"
},
"type": "module",
"dependencies": {
"user-credits": "0.9.4-alpha"
},
"devDependencies": {
"typescript": "^5.2.2"
}
}
Now it complains with the error
src/test.ts:1:36 - error TS2307: Cannot find module 'user-credits' or its corresponding type declarations.
1 import { IOffer, OfferCycle } from 'user-credits';
~~~~~~~~~~~~~~
I started this test project because I lost an entire day trying to fix the error below on my sveltekit project.
ReferenceError: exports is not defined
So I thought I'd verify that user-credits
is properly published. The testing project here has a single test.ts
file.
I don't want to enter into details about how user-credits
is structured, as I think there's something I'm missing about using exactly the same project locally then publishing it and having a different behavior.
Ok,
Updating it and publishing worked as expected: