Hi i am creating 2 simple test projects where project A is a custom NPM package and project B consume it. When running it through es-dev-server i get Error: Could not resolve import “npm-project-a” in “src/index.ts”.
My folder structure looks like this:
project-a/src/index.ts
export function MRTAdd(v1: number, v2: number): number {
return v1 + v2;
}
project-a/package.json
{
"name": "npm-project-a",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"module": "commonjs",
"scripts": {
"build": "tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"lodash": "^4.17.21"
}
}
project-a/tsconfig.json
{
"compilerOptions": {
"target": "es2016",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "commonjs",
"declaration": true,
"declarationMap": true,
"outDir": "./dist",
"skipLibCheck": true
}
}
Next i ran npm build
which gives me the tsc build inside dist folder
Next step i did is to npm link
inside root of project-a, and then in project-b i npm link npm-project-a
Now inside project-b/src/index.ts
import { MRTAdd } from 'npm-project-a';
console.log(MRTAdd(1, 2));
My index.html is referencing <script src="index.ts"></script>
Then when running command in project-b/package.json
"scripts": {
"start": "es-dev-server --app-index src/index.html --node-resolve --watch --open"
},
i get this error
Please advise!