docker-compose
docker-compose copied to clipboard
Docker-Compose V2 && ESM + TypeScript
I am attempting to use docker-compose in an ESM module with typescript. My preference is to use the forth coming v2 version so my import definition looks like:
import compose from 'docker-compose/dist/v2';
However, TypeScript is giving me the error:
Cannot find module 'docker-compose/dist/v2' or its corresponding type declarations.ts(2307)
I see the types in the distribution at node_modules/docker-compose/dist/v2.d.ts but those types do not expand the "module" definition.
Meaning, updating my tsconfig.json to be something like:
{
"include": [
"**/*.ts",
"../../node_modules/docker-compose/dist/v2.d.ts"
],
}
Does not fix the issue, because the v2.d.ts does not tell TypeScript something lives at "dist/v2".
What is the best way to import the types for v2?
Can you please share your Node.js and Typescript versions and your complete tsconfig?
node 20.12
{
"compilerOptions": {
"moduleResolution": "NodeNext",
"module": "NodeNext",
"target": "ESNext",
"isolatedModules": true,
"lib": [
"ESNext"
],
"declaration": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": false,
"resolveJsonModule": true,
"esModuleInterop": true,
"inlineSourceMap": false,
"inlineSources": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"strictPropertyInitialization": false,
"sourceMap": true,
"skipLibCheck": true
}
}
Note: I think the v2.d.ts needs something like:
declare module 'docker-compose/dist/v2' {
...
}
Then it would be possible to do the following in the tsconfig.json:
{
"include": [
"**/*.ts",
"../../node_modules/docker-compose/dist/v2.d.ts"
],
}
But I'm certainly no expert on this
I'm working on it at #277 but it doesn't work yet (e.g. 0.24.9-alpha.4).