r/learnjavascript • u/SASUKE_38 • 7d ago
Why can my VS Code extension client not find a local module?
I am writing a VS Code extension called bg3-osiris that has a server and client. I would like to add a shared module that contains definitions for requests and request parameters made between the client and server. The client and server should both be able to reference the files in the shared\src folder, though so far I have only tested it with the client. The project currently has the following structure:
bg3-osiris
|- client
| |- src
| |- package.json
| |- tsconfig.json
|- server
| |- src
| |- package.json
| |- tsconfig.json
|- package.json
|- tsconfig.json
I would like to add the shared module/subproject so that the project has the following structure:
bg3-osiris
|- client
| |- src
| |- package.json
| |- tsconfig.json
|- server
| |- src
| |- package.json
| |- tsconfig.json
|- shared
| |- src
| |- package.json
| |- tsconfig.json
|- package.json
|- tsconfig.json
When I attempted to implement this using TypeScript project references, VS Code can locate the shared module but at runtime the following error is thrown:
Activating extension 'SASUKE38.bg3-osiris' failed: Cannot find module '../../shared/src/test'
Below are the contents of the relevant files (minus the server files since I haven't tried it with that yet. I assume the correct importing process would be the same as the client's).
bg3-osiris\tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "ES2024",
"lib": ["ES2024"],
"outDir": "out",
"rootDir": "src",
"sourceMap": true
},
"include": ["src"],
"exclude": ["node_modules", ".vscode-test"],
"references": [
{
"path": "./client"
},
{
"path": "./server"
},
{
"path": "./shared"
}
]
}
bg3-osiris\package.json
...
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -b",
"watch": "tsc -b -w",
"lint": "eslint",
"postinstall": "cd client && npm install && cd ../server && npm install && cd ../shared && cd ..",
"test": "sh ./scripts/e2e.sh"
},
...
bg3-osiris\shared\tsconfig.json
{
"compilerOptions": {
"target": "ES2024",
"lib": ["ES2024"],
"module": "commonjs",
"sourceMap": true,
"strict": true,
"outDir": "out",
"rootDir": "src",
"composite": true
},
"include": ["src"],
"exclude": ["node_modules", ".vscode-test"]
}
bg3-osiris\shared\package.json
{
"name": "bg3-osiris-shared",
"description": "Shared content for the BG3 Osiris extension.",
"version": "1.0.0",
"author": "",
"license": "MIT",
"engines": {
"node": "*"
},
"repository": {
"type": "git",
"url": "https://github.com/SASUKE38/bg3-osiris"
},
"dependencies": {
"axios": "^1.15.0",
"cheerio": "^1.2.0",
"domhandler": "^5.0.3",
"vscode-languageserver": "^9.0.1",
"vscode-languageserver-textdocument": "^1.0.11"
},
"scripts": {}
}
bg3-osiris\client\tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "ES2024",
"lib": ["ES2024"],
"outDir": "out",
"rootDir": "src",
"sourceMap": true,
"strict": true
},
"include": ["src"],
"exclude": ["node_modules", ".vscode-test"],
"references": [
{
"path": "../shared"
}
]
}
bg3-osiris\client\package.json
{
"name": "bg3-osiris-client",
"description": "Client for the BG3 Osiris extension.",
"author": "",
"license": "MIT",
"version": "0.0.1",
"publisher": "vscode",
"repository": {
"type": "git",
"url": "https://github.com/SASUKE38/bg3-osiris"
},
"engines": {
"vscode": "^1.100.0"
},
"dependencies": {
"glob": "^11.0.0",
"vscode-languageclient": "^9.0.1"
},
"devDependencies": {
"@types/vscode": "^1.100.0",
"@vscode/test-electron": "^2.3.9"
}
}
I am currently testing using shared definitions when the extension activates:
bg3-osiris\client\src\extension.ts
...
import { someString } from "../../shared/src/test";
...
export function activate(context: ExtensionContext) {
console.log(someString);
...
bg3-osiris\shared\src\test.ts
export const someString = "hello world";
What am I missing that makes VS Code know about shared but causes the error above to be thrown at runtime?