错误 TS1005:预期为“,”。导入 { 类型 ParserOptions }

问题描述 投票:0回答:2

这是我的package.json

{
  "main": "index.js",
  "scripts": {
    "prebuild": "rimraf dist && tsc",
    "prod": "knex migrate:latest --env production && ts-node -r tsconfig-paths/register dist/index.js",
  }, 
  "dependencies": {
    "@types/aws-sdk": "^2.7.0",
    "@types/axios": "^0.14.0",
    "@types/convict": "^6.1.3",
    "@types/knex": "^0.16.1",
    "@types/lodash": "^4.14.197",
    "@types/morgan": "^1.9.5",
    "@types/multer": "^1.4.7",
    "@types/uuid": "^9.0.2",
    "ajv": "^8.6.3",
    "aws-sdk": "^2.1445.0",
    "axios": "^1.4.0",
    "base64url": "^3.0.1",
    "convict": "^6.2.1",
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "express-http-context": "^1.2.4",
    "html-to-pdfmake": "^2.4.25",
    "https": "^1.0.0",
    "js-yaml": "^4.1.0",
    "jsdom": "^22.1.0",
    "jsonwebtoken": "^8.5.1",
    "jws": "^4.0.0",
    "knex": "^0.95.15",
    "lodash": "^4.17.21",
    "merge": "^2.1.1",
    "moment": "^2.29.1",
    "moment-timezone": "^0.5.34",
    "morgan": "^1.10.0",
    "multer": "^1.4.5-lts.1",
    "node-cache": "^5.1.2",
    "nodemailer": "^6.9.5",
    "nodemon": "^3.0.1",
    "papaparse": "^5.3.2",
    "path": "^0.12.7",
    "pdfmake": "^0.2.7",
    "pg": "^8.7.1",
    "redis": "^4.1.0",
    "socket.io": "^4.5.0",
    "string-strip-html": "^8.3.0",
    "textract": "^2.5.0",
    "typescript": "4.4.3",
    "ulid": "^2.3.0",
    "uuid": "^8.3.2",
    "winston": "^3.3.3",
    "yaml": "^2.2.1"
  },
  "devDependencies": {
    "@types/html-to-pdfmake": "^2.4.2",
    "@types/jest": "^28.1.3",
    "@types/jsdom": "^21.1.3",
    "@types/nodemailer": "^6.4.11",
    "@types/pdfmake": "^0.2.4",
    "jest": "^28.1.3",
    "ts-jest": "^28.0.8",
    "ts-node": "^10.2.1",
    "ts-node-dev": "^1.1.8",
    "tsconfig-paths": "^3.12.0",
    "typescript": "4.4.3"
  },
 
}

这是 tsconfig 文件

{
"compilerOptions": {
  "target": "es5",
  "module": "commonjs",
  "rootDir": ".",
  "baseUrl": "./src",
  "outDir": "dist",
  "esModuleInterop": true,
  "moduleResolution": "node",
  "allowSyntheticDefaultImports": true,
  "lib": [
    "esnext",
    "dom"
  ],
  "forceConsistentCasingInFileNames": true,
  "strict": true,
  "skipLibCheck": true,
  "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
  }
}

这是我的Makefile

# # Stage 1: Build Stage
FROM node:19.9.0-alpine3.17
WORKDIR /app
COPY package.json ./
COPY tsconfig.json ./
# RUN apk add --no-cache \
RUN apk add  \
    make \
    && npm install
COPY . .
RUN npm install -g knex
RUN npm run prebuild

# Stage 2: Runtime Stage
EXPOSE 8055
CMD ["npm", "run", "prod"]

我在构建时遇到错误

[8/8] RUN npm 运行预构建: 0.483 0.483 > [电子邮件受保护] 预构建 0.483 > 边缘拉夫区 && tsc 0.483 9.352 node_modules/parse5/dist/index.d.ts(1,15):错误 TS1005:预期为“,”。 9.353 node_modules/parse5/dist/index.d.ts(4,15):错误 TS1005:预期为“,”。 9.353 node_modules/parse5/dist/index.d.ts(6,15):错误 TS1005:预期为“,”。 9.354 node_modules/parse5/dist/index.d.ts(7,42):错误 TS1005:预期为“,”。 9.354 node_modules/parse5/dist/index.d.ts(8,34):错误 TS1005:预期为“,”。 9.354 node_modules/parse5/dist/index.d.ts(16,26):错误 TS1005:预期为“,”。 9.354 node_modules/parse5/dist/index.d.ts(16,64):错误 TS1005:预期为“,”。

node.js typescript makefile package.json
2个回答
3
投票

错误指出了第一个

import

import { Parser, type ParserOptions } from './parser/index.js';
//                    ^ error TS1005: ',' expected.

tsc
需要一个用于新命名导入的分隔符,而这里我们有一个
type
关键字。

TypeScript

4.5 版中引入了带有“内联”
type修饰符的命名导入

[...] 最好避免同一模块有两个 import 语句。这就是为什么 TypeScript 4.5 允许对单个命名导入使用类型修饰符的部分原因,以便您可以根据需要进行混合和匹配。

...而您的

package.json
需要:

"typescript": "4.4.3"

因此,如果您的项目允许,您只需将

typescript
devDependency 更新到版本 4.5+ 就可以了。


-1
投票

enter image description here

enter image description here

我的ts版本是4.5.5。它将检查node_modules中的包。怎么处理这个问题?

© www.soinside.com 2019 - 2024. All rights reserved.