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

Wrong output destination for declarations #481

Closed
tunnckoCore opened this issue Oct 20, 2019 · 2 comments · Fixed by #627
Closed

Wrong output destination for declarations #481

tunnckoCore opened this issue Oct 20, 2019 · 2 comments · Fixed by #627

Comments

@tunnckoCore
Copy link

tunnckoCore commented Oct 20, 2019

It generates

yarn run v1.17.3
$ /home/charlike/github/tunnckoCore/opensource/node_modules/.bin/ncc build src/index.ts
ncc: Version 0.20.5
ncc: Compiling file index.js
ncc: Using [email protected] (local user-provided)
  0kB  dist/home/charlike/github/tunnckoCore/opensource/packages/parse-function/dist/typings/test/index.d.ts
  0kB  dist/home/charlike/github/tunnckoCore/opensource/packages/parse-function/dist/typings/test/index.d.ts.map
  0kB  dist/home/charlike/github/tunnckoCore/opensource/packages/parse-function/dist/typings/src/utils.d.ts.map
  0kB  dist/home/charlike/github/tunnckoCore/opensource/packages/parse-function/dist/typings/src/index.d.ts
  0kB  dist/home/charlike/github/tunnckoCore/opensource/packages/parse-function/dist/typings/src/index.d.ts.map
  0kB  dist/home/charlike/github/tunnckoCore/opensource/packages/parse-function/dist/typings/src/plugins/props.d.ts.map
  0kB  dist/home/charlike/github/tunnckoCore/opensource/packages/parse-function/dist/typings/src/plugins/params.d.ts
  0kB  dist/home/charlike/github/tunnckoCore/opensource/packages/parse-function/dist/typings/src/plugins/params.d.ts.map
  0kB  dist/home/charlike/github/tunnckoCore/opensource/packages/parse-function/dist/typings/src/plugins/initial.d.ts
  0kB  dist/home/charlike/github/tunnckoCore/opensource/packages/parse-function/dist/typings/src/plugins/initial.d.ts.map
  0kB  dist/home/charlike/github/tunnckoCore/opensource/packages/parse-function/dist/typings/src/plugins/body.d.ts
  0kB  dist/home/charlike/github/tunnckoCore/opensource/packages/parse-function/dist/typings/src/plugins/body.d.ts.map
  1kB  dist/home/charlike/github/tunnckoCore/opensource/packages/parse-function/dist/typings/src/utils.d.ts
  1kB  dist/home/charlike/github/tunnckoCore/opensource/packages/parse-function/dist/typings/src/types.d.ts
  1kB  dist/home/charlike/github/tunnckoCore/opensource/packages/parse-function/dist/typings/src/types.d.ts.map
  1kB  dist/home/charlike/github/tunnckoCore/opensource/packages/parse-function/dist/typings/src/plugins/props.d.ts
346kB  dist/index.js
350kB  [5235ms] - ncc 0.20.5
Done in 5.52s.

The tsconfig inside the package root is

{
  "$schema": "http://json.schemastore.org/tsconfig",
  "compilerOptions": {
    "declarationDir": "./dist/typings",
    "typeRoots": [
      "./node_modules/@types",
      "../../node_modules/@types",
      "../../@types"
    ],
    "skipLibCheck": true,
    "alwaysStrict": true,
    "newLine": "LF",
    "declaration": true,
    "declarationMap": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": false,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "importHelpers": true,
    "incremental": false,
    "jsx": "react",
    "lib": ["dom", "esnext"],
    "module": "esnext",
    "moduleResolution": "node",
    // "noEmit": true,
    "strict": true,
    "sourceMap": true,
    "stripInternal": true,
    "noUnusedLocals": true,
    "noImplicitReturns": true,
    "resolveJsonModule": true,
    "noUnusedParameters": true,
    "target": "esnext",
    "rootDir": "src",
    "outDir": "dist",
    "baseUrl": "."
  },
  "exclude": ["test"]
}

With the tsc it is correct ./dist/typings

The current workaround is

{
  "scripts": {
    "prebuild": "rm -rf dist",
    "build": "ncc build src/index.ts -sm -o dist/main",
    "postbuild": "mv \"dist/main/$PWD/dist/typings\" dist && rm -rf dist/main/home"
  }
}
@KusStar
Copy link

KusStar commented Jun 20, 2020

I found a way to avoid it by chance.
Just use / not ./.

Example:

{
  "compilerOptions": {
    "declaration": true,
    "declarationDir": "/typings"
  }
}

Env:

{
	"devDependencies": {
	    "@zeit/ncc": "^0.22.3",
	    "typescript": "^3.9.5"
  	}
}

@tunnckoCore
Copy link
Author

Thanks, I'll try it some time.

styfle pushed a commit that referenced this issue Jan 11, 2021
If declarationDir is special, the output dir will be unexpected, fixes #481, and I run typescript example will cause same error as follow
![image](https://user-images.githubusercontent.com/32335736/102162314-ec5d1480-3ec3-11eb-91e5-b45afab4211c.png)

`tsconfig.json` as follow
![image](https://user-images.githubusercontent.com/32335736/102162468-334b0a00-3ec4-11eb-835a-789bff388307.png)

I give a quick fix, rewrite dir before write file into disk, seems can fix the problem.
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

Successfully merging a pull request may close this issue.

2 participants