developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8.04k stars 362 forks source link

Using baseUrl in tsconfig creates broken packages #916

Closed pomle closed 2 years ago

pomle commented 2 years ago

When defining baseUrl in tsconfig.json to avoid excessive parent traversing ../../../.. the local project will recognize everything as okay, but the build output will contain broken imports.

Consider the example below; src file to the left, dist file to the right. image

tsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "lib": ["dom", "esnext"],
    "allowJs": true,
    "baseUrl": "src",
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "downlevelIteration": true,
    "noEmit": true
  },
  "exclude": ["node_modules", "dist"]
}

package.json

{
  "name": "api-client",
  "version": "0.0.2-0",
  "description": "API client for JavaScript and TypeScript",
  "author": "Pontus Persson <pontus@RETRACTED>",
  "license": "UNLICENSED",
  "type": "module",
  "source": "src/index.ts",
  "module": "./dist/index.modern.js",
  "main": "./dist/index.js",
  "scripts": {
    "build": "microbundle",
    "dev": "microbundle watch",
    "test": "jest"
  },
  "exports": {
    "require": "./dist/index.cjs",
    "default": "./dist/index.modern.js"
  },
  "files": [
    "dist"
  ],
  "devDependencies": {
    "@types/jest": "^26.0.15",
    "@types/node": "^12.0.0",
    "jest": "^27.4.5",
    "microbundle": "^0.14.2",
    "prettier": "^2.5.1",
    "ts-jest": "^27.1.1",
    "ts-node": "^10.4.0",
    "typescript": "^4.5.4"
  }
}
developit commented 2 years ago

I don't think Microbundle rewrites any imports/paths in type definition files, it only moves them.

pomle commented 2 years ago

You are right. I expected to be warned, or handled, if something was awry.