Module not found when running tsup in watch mode
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 275
- PR merge metrics
- No merged PRs in 30d
Description
If iI run tsup fur bundling my types everythings working fine and everythings working as I expected.
But if I run tsup --watch i get Following Error:
```
Cannot find module 'xxxxxx/apps/backend/node_modules/types/dist'
backend:dev: at createEsmNotFoundErr (node:internal/modules/cjs/loader:1177:15)
backend:dev: at finalizeEsmResolution (node:internal/modules/cjs/loader:1165:15)
backend:dev: at resolveExports (node:internal/modules/cjs/loader:590:14)
backend:dev: at Function.Module._findPath (node:internal/modules/cjs/loader:664:31)
backend:dev: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1126:27)
backend:dev: at Function.Module._load (node:internal/modules/cjs/loader:981:27)
backend:dev: at Module.require (node:internal/modules/cjs/loader:1231:19)
backend:dev: at require (node:internal/modules/helpers:177:18)
backend:dev: at Object. (xxxxxxx/apps/backend/src/auth/auth.controller.ts:10:1)
backend:dev: at Module._compile (node:internal/modules/cjs/loader:1364:14)
```
What could be the problem here? When I look into the node_modules they are perfectly there.
package.json
```
{
"name": "types",
"version": "1.0.0",
"description": "",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"exports": {
".": "./dist",
"./confluence-v1": "./dist/confluence-v1.mjs",
"./confluence-v2": "./dist/confluence-v2.mjs"
},
"typesVersions": {
"*": {
".": [
"./dist/index.d.ts"
],
"confluence-v1": [
"./dist/confluence-v1.d.ts"
],
"confluence-v2": [
"./dist/confluence-v2.d.ts"
]
}
},
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"gen:api": "npx openapi-typescript https://dac-static.atlassian.com/cloud/confluence/swagger.v3.json -o confluence-v1.ts && npx openapi-typescript https://dac-static.atlassian.com/cloud/confluence/openapi-v2.json -o confluence-v2.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"eslint-config-custom": "workspace:^",
"tsconfig": "workspace:^",
"tsup": "^7.2.0",
"typescript": "^5.4.5"
}
}
```
tsup.config.ts
```
import type { Options } from "tsup";
import { defineConfig } from "tsup";
export default defineConfig((options: Options) => ({
treeshake: true,
splitting: true,
entry: ["src/**/*.ts"],
format: ["esm"],
dts: true,
minify: true,
clean: true,
...options,
}));
```
tsconfig.json
```
{
"extends": "tsconfig/ts-library.json",
"include": ["."],
"exclude": ["dist", "node_modules"],
"compilerOptions": {
"outDir": "dist"
}
}
```
ts-library.json
```
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Typescript Library",
"extends": "./base.json",
"compilerOptions": {
"lib": ["dom", "ES6", "ES2017"],
"module": "ESNext",
"target": "es6"
}
}
```
base.json
```
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Default",
"compilerOptions": {
"composite": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"moduleResolution": "node",
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
"skipLibCheck": true,
"strict": true
},
"exclude": ["node_modules"]
}
```
Maybe I just do something wrong
Contributor guide
Research direction
Start by reproducing the failure with the provided package.json, tsup.config.ts, tsconfig.json, and workspace setup, comparing a normal build with tsup --watch. Inspect the package exports and the import from backend/src/auth/auth.controller.ts, then verify that watch mode resolves the generated dist entry consistently and that the backend starts without the module-not-found error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100