1

I have a problem with my vscode extension having both client and server sides. There's also a shared folder used for both the server and client sides. I'm trying to include @shared/* but it gives me the error shown on screenshot.

I've tried many methods, but it seems like something is still missing.

// tsconfig.json
{
    "compilerOptions": {
        "module": "commonjs",
        "target": "ES2022",
        "lib": [
            "ES2022"
        ],
        "baseUrl": ".",
        "rootDir": ".",
        "outDir": "out",
        "sourceMap": true,
        "composite": true,
        "declaration": true,
        "declarationMap": true,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,
        "resolveJsonModule": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "skipLibCheck": true
    },
    "include": [
        "*.ts"
    ],
    "exclude": [
        "node_modules"
    ],
    "references": [
        {
            "path": "client"
        },
        {
            "path": "server"
        },
        {
            "path": "shared"
        }
    ]
}
// client/tsconfig.json
{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2022",
        "lib": [
            "es2022"
        ],
        "rootDir": "src",
        "outDir": "out",
        "baseUrl": "..",
        "tsBuildInfoFile": ".tsbuildinfo",
        "paths": {
            "@shared/*": [
                "shared/src/*"
            ]
        },
        "strict": true,
        "sourceMap": true
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules"
    ],
    "references": [
        {
            "path": "../shared"
        }
    ]
}
// server/tsconfig.json
{
    "compilerOptions": {
        "module": "commonjs",
        "lib": [
            "es2022"
        ],
        "target": "es2022",
        "rootDirs": [
            "src"
        ],
        "outDir": "out",
        "baseUrl": "..",
        "tsBuildInfoFile": ".tsbuildinfo",
        "paths": {
            "@shared/*": [
                "shared/src/*"
            ]
        },
        "composite": true,
        "declaration": true,
        "declarationMap": true,
        "strict": true,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,
        "sourceMap": true,
        "esModuleInterop": true
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules"
    ],
    "references": [
        {
            "path": "../shared"
        }
    ]
}
// shared/tsconfig.json
{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2022",
        "lib": [
            "es2022"
        ],
        "rootDir": "src",
        "baseUrl": "..",
        "outDir": "out",
        "tsBuildInfoFile": ".tsbuildinfo",
        "composite": true,
        "sourceMap": true,
        "declaration": true,
        "declarationMap": true,
        "strict": true
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules"
    ]
}
// client/src/extension.ts
import { StorageDataManager } from '@shared/storage-data-manager';

This line causes an error

3
  • Do you have any code that can resolve '@shared/storage-data-manager' at runtime? Or are you using a bundler/other tool that will rewrite your code when you build it? As the documentation says: "this feature does not change how import paths are emitted by tsc, so paths should only be used to inform TypeScript that another tool has this mapping and will use it at runtime or when bundling". Commented Sep 20 at 15:04
  • No, I don't have. I try to use module-alias, but nothing works for me Commented Sep 20 at 15:18
  • Maybe there's an example of some vscode extension somewhere that uses module-alias and has a client, server, and shared sides? Commented Sep 20 at 15:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.