Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module not found when running tsup in watch mode #1126

Open
chrisanvil opened this issue May 17, 2024 · 0 comments
Open

Module not found when running tsup in watch mode #1126

chrisanvil opened this issue May 17, 2024 · 0 comments

Comments

@chrisanvil
Copy link

chrisanvil commented May 17, 2024

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.<anonymous> (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

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant