unbuild icon indicating copy to clipboard operation
unbuild copied to clipboard

some ts error

Open classmatewu opened this issue 2 years ago • 3 comments

There some errors when I npx unbuild

src/index.ts(1,8): error TS1259: Module '"/path/to/node_modules/@types/express/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag?

why and what shoud I do?

classmatewu avatar Sep 15 '22 07:09 classmatewu

I was going to take a look at this issue of yours but since there is no minimal recreation, please provide one 🤙🏼

chrisbbreuer avatar Sep 15 '22 09:09 chrisbbreuer

There is my package.json~

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "dev": "tsx watch ./src/app.ts",
    "build": "unbuild",
    "prepack": "unbuild",
    "release": "bumpp && npm publish"
  },
  "type": "module",
  "exports": {
    ".": {
      "import": "./dist/index.mjs",
      "require": "./dist/index.cjs"
    }
  },
  "main": "./dist/index.cjs",
  "types": "./dist/index.d.ts",
  "files": [
    "dist"
  ],
  "repository": {
    "type": "git",
    "url": ""
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.18.1"
  },
  "devDependencies": {
    "@types/express": "^4.17.14",
    "bumpp": "^8.2.1",
    "tsx": "^3.9.0",
    "typescript": "^4.8.3",
    "unbuild": "^0.8.11"
  }
}

classmatewu avatar Sep 15 '22 12:09 classmatewu

You can always configure allowSyntheticDefaultImports in your tsconfig. But you also should probably not import from @types/express - just import the type from express.

danielroe avatar Sep 15 '22 12:09 danielroe