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

Invalid TypeScript declaration files (.d.ts) emitted when mono-repo modules are being referred. #7400

Closed
SayBGM opened this issue Dec 3, 2021 · 4 comments

Comments

@SayBGM
Copy link

SayBGM commented Dec 3, 2021

🐛 bug report

It seems Parcel fails to emit valid TypeScript declaration files (.d.ts) when the input source is importing any of its mono-repo related modules.

https://github.com/Mint-SayBGM/parcel-typescript-interface-error

🎛 Configuration (.babelrc, package.json, cli command)

package.json

{
  "name": "root",
  "private": true,
  "devDependencies": {
    "@babel/core": "^7.16.0",
    "@babel/preset-env": "^7.16.0",
    "@parcel/packager-ts": "^2.0.1",
    "@parcel/transformer-typescript-types": "^2.0.1",
    "@parcel/config-default": "^2.0.1",
    "@parcel/transformer-typescript-tsc": "^2.0.1",
    "@swc/helpers": "^0.2.13",
    "@typescript-eslint/eslint-plugin": "^5.1.0",
    "@typescript-eslint/parser": "^5.1.0",
    "eslint": "^7.11.0",
    "eslint-plugin-react": "^7.26.1",
    "lerna": "^4.0.0",
    "parcel": "^2.0.1",
    "typescript": "^4.4.4"
  },
  "scripts": {
    "prepare": "lerna run prepare",
    "dev": "lerna run dev --stream",
    "build": "yarn & lerna run build --stream",
    "bootstrap": "lerna bootstrap --use-workspaces"
  },
  "workspaces": [
    "packages/*"
  ]
}

packages/sdk/package.json

{
  "name": "@modules/sdk",
  "version": "0.0.1",
  "license": "ISC",
  "baseUrl": "./src",
  "types": "dist/index.d.ts",
  "main": "dist/index.js",
  "targets": {
    "main": {
      "optimize": true
    }
  },
  "scripts": {
    "prepublishOnly": "yarn build",
    "dev": "yarn build",
    "build": "yarn parcel build src/index.ts",
    "start": "yarn parcel src/index.ts"
  }
}

packages/types/package.json

{
  "name": "@modules/types",
  "version": "1.0.0",
  "private": true,
  "description": "> TODO: description",
  "homepage": "",
  "license": "ISC",
  "types": "dist/index.d.ts",
  "main": "dist/index.js",
  "scripts": {
    "prepare": "yarn build",
    "build": "yarn parcel build index.ts"
  }
}

🤔 Expected Behavior

packages/sdk/dist/index.d.ts

import { AddressItem } from "@modules/types";
export const getZoneCode: (address: AddressItem) => Promise<string>;

//# sourceMappingURL=index.d.ts.map

😯 Current Behavior

packages/sdk/dist/index.d.ts

import { AddressItem as  } from "@modules/types";
export const getZoneCode: (address: AddressItem) => Promise<string>;

//# sourceMappingURL=index.d.ts.map

💁 Possible Solution

Note that I could not reproduce this behavior with TSC so seems like it’s somewhat relates to Parcel’s own build pipeline.

💻 Code Sample

https://github.com/Mint-SayBGM/parcel-typescript-interface-error

🌍 Your Environment

Software Version(s)
Parcel ^2.0.1
Node v14.18.2
npm/Yarn yarn v1.22.17
Operating System Mac BigSur (11.4)
typescript ^4.4.4
@SayBGM SayBGM changed the title A phenomenon in which the TypeScript interface is not normally detected when build. Invalid TypeScript declaration files (.d.ts) emitted when mono-repo modules are being referred. Dec 3, 2021
@benpigchu
Copy link

Maybe this is a duplicate of #7325 ?

@astegmaier
Copy link
Contributor

I think that #7426 might fix this. However, in the repro steps above, show typescript ^4.4.4 as the dependency (which is somewhat ambiguous, because npm/yarn might install a higher version). @Mint-SayBGM - can you confirm the exact version of typescript that is installed when you get the repro? And see if downgrading to version 4.4.x or earlier fixes the problem?

@benpigchu
Copy link

@astegmaier In the yarn.lock from the code sample repo:

https://github.com/Mint-SayBGM/parcel-typescript-interface-error/blob/2c02afa69f121976c0a16fcddabe6107a3f63dd9/yarn.lock#L8616-L8619

The actual installed version of typescript should be 4.5.2

@SayBGM
Copy link
Author

SayBGM commented Dec 13, 2021

I confirmed that downgrading the typescript version solved it.

Thanks so much! @benpigchu

@SayBGM SayBGM closed this as completed Dec 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants