My latest project involves a unique library with only one export, an interface named IBasic. After publishing this library on npm and installing it in another project, I encountered an issue. When attempting to import IBasic using the auto-import feature (ctrl+.), it couldn't be found. However, manually specifying the path as
import { IBasic } from "node_modules/<libraryname>/src"
resolved the problem.
So, the question arises: How can I ensure that my library's interface works seamlessly with auto-import functionality when installed in a project?
Details of the library package.json:
{
"name": "enzotypes",
"version": "1.0.1",
"description": "types library test",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rollup -c --bundleConfigAsCjs"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
...
},
"peerDependencies": {
"react": "^18.2.0"
}
}
Now, looking at the project's package.json:
{
"name": "[...]",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
...
},
"dependencies": {
[...]
"enzotypes": "^1.0.1",
[...]
},
"devDependencies": {
[...]
}
}