vercel / ncc

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.
https://npmjs.com/@vercel/ncc
MIT License
9.11k stars 289 forks source link

Option 'allowImportingTsExtensions' can only be used when either 'noEmit' or 'emitDeclarationOnly' is set. #1146

Open lohrm-stabl opened 9 months ago

lohrm-stabl commented 9 months ago

Hello,

I get the following error:

ncc: Version 0.38.1
ncc: Compiling file index.js into ESM
ncc: Using typescript@5.3.2 (local user-provided)
Error: [tsl] ERROR
      TS5096: Option 'allowImportingTsExtensions' can only be used when either 'noEmit' or 'emitDeclarationOnly' is set.
    at /workspaces/SBC-Device-API/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:38:1896272
    at /workspaces/SBC-Device-API/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:38:396262
    at _done (eval at create (/workspaces/SBC-Device-API/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:21:75523), <anonymous>:9:1)
    at eval (eval at create (/workspaces/SBC-Device-API/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:21:75523), <anonymous>:34:22)
error: "ncc" exited with code 1 (SIGHUP)

While I have both "allowImportingTsExtensions": true, and noEmit: true in my tsconfig.

Full config:

// https://gist.github.com/slavafomin/cd7a54035eff5dc1c7c2eff096b23b6b
{
  "$schema": "https://json.schemastore.org/tsconfig",
  "compilerOptions": {
    // From: https://github.com/tsconfig/bases/blob/main/bases/node20.json
    "lib": [
      "es2023"
    ],
    "module": "node16",
    "target": "es2022",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "moduleResolution": "node16",
    "allowSyntheticDefaultImports": true,
    // Most from: https://github.com/tsconfig/bases/blob/main/bases/strictest.json
    "allowUnusedLabels": false,
    "allowUnreachableCode": false,
    "exactOptionalPropertyTypes": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "noPropertyAccessFromIndexSignature": true, // Conflicts with https://eslint.org/docs/latest/rules/dot-notation
    "noUncheckedIndexedAccess": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "isolatedModules": true,
    "checkJs": true,
    // Custom
    "baseUrl": "./",
    "rootDir": "./src",
    "noEmit": true, // We use ncc to build our code
    "preserveConstEnums": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "allowImportingTsExtensions": true,
    "typeRoots": [
      "./node_modules/@types",
    ],
    "types": [
      "node"
    ]
  },
  "include": [
    "./src/**/*.ts"
  ],
  "exclude": [
    "./src/public/",
    "build.cjs",
    "dist/*"
  ],
  "ts-node": {
    "esm": true,
    "experimentalSpecifierResolution": "node",
  }
}
ejkg commented 5 months ago

I am also experiencing this same issue and I have a much simpler tsconfig.

{
  "extends": "@tsconfig/node20/tsconfig.json",
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "emitDeclarationOnly": true,
    "composite": true,
    "esModuleInterop": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "outDir": "dist",
    "rootDir": "../../",
    "baseUrl": ".",
  }
}

When I run:

$ pnpm build

I get this error:

ncc: Version 0.38.1
ncc: Compiling file index.js into ESM
ncc: Using typescript@5.4.4 (local user-provided)
Error: Module build failed (from ../../node_modules/.pnpm/@vercel+ncc@0.38.1/node_modules/@vercel/ncc/dist/ncc/loaders/ts-loader.js):
Error: TypeScript emitted no output for /path/to/entry/index.ts.

Here is a sample of my package.json as well.

{
  "name": "package-namespace/a",
  "main": "dist/index.js",
  "type": "module",
  "version": "0.0.0",
  "scripts": {
    "build": "ncc build index.ts --out dist --no-cache --debug"
  },
  "dependencies": {
    "library-namespace/a": "workspace:*",
    "library-namespace/b": "workspace:*",
    "library-namespace/c": "workspace:*"
  },
  "devDependencies": {
    "@tsconfig/node20": "^20.1.4",
    "@types/node": "^20.12.4",
    "typescript": "^5.4.4"
  }
}