I have a NextJs (host) app and a separate utility package published to Github's registry. I want to be able to debug and iterate on the utility package locally when running the logic from my NextJs app.
The utility package compiles typescript to a dist/index.js folder, and index.js exports a class. I run npm run build and ensure the dist assets are present.
I configure the host app to use the file system to import the package locally:
"dependencies": {
...
"@my-company/utils": "file:../utility-package"
},
I run npm i. I can see node_modules/@my-company/utils and the dist folder.
In the host app import the utility class, and VSCode sees the import/package just fine.
import { TestService } from "@my-company/utils";
console.log(TestService.helloWorld());
In the browser I get Module not found: Can't resolve '@my-company/utils'.
I suspect something is not quite right with my utility library package.json (or perhaps the compiled index.js file).
Utility library package.json
{
"name": "@my-company/utils",
"version": "1.0.3",
"description": "",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"exports": {
".": {
"import": "./dist/index.js"
}
},
"scripts": {
"build": "tsc",
"prepublishOnly": "npm run build"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com/"
},
"repository": {
"type": "git",
"url": "git+https://github.com/my-company/utils.git"
},
"devDependencies": {
...
},
"dependencies": {
...
}
}
Utility library tsconfig.json
{
"compilerOptions": {
"target": "ES2020",
"module": "ES2020",
"moduleResolution": "bundler",
"declaration": true,
"outDir": "dist",
"strict": true,
"esModuleInterop": true
},
"include": ["src"]
}
Utility library compiled dist/index.js
export { TestService } from "./services/TestService";
I also have a Github repo demonstrating this here.
I've tried every alternative chatGPT has to offer but this is the simplest reproduction case.

