Search code examples
node.jstypescriptmakefilepackage.json

error TS1005: ',' expected. import { type ParserOptions }


Here is my 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"
  },
 
}

This is tsconfig file

{
"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. */
  }
}

This is my 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"]

I am getting error on build

[8/8] RUN npm run prebuild: 0.483 0.483 > project@1.0.0 prebuild 0.483 > rimraf dist && tsc 0.483 9.352 node_modules/parse5/dist/index.d.ts(1,15): error TS1005: ',' expected. 9.353 node_modules/parse5/dist/index.d.ts(4,15): error TS1005: ',' expected. 9.353 node_modules/parse5/dist/index.d.ts(6,15): error TS1005: ',' expected. 9.354 node_modules/parse5/dist/index.d.ts(7,42): error TS1005: ',' expected. 9.354 node_modules/parse5/dist/index.d.ts(8,34): error TS1005: ',' expected. 9.354 node_modules/parse5/dist/index.d.ts(16,26): error TS1005: ',' expected. 9.354 node_modules/parse5/dist/index.d.ts(16,64): error TS1005: ',' expected.


Solution

  • The error points out to the very first import line:

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

    tsc expects a separator for a new named import, whereas here we have a type keyword.

    This named import with "inline" type modifier has been introduced in TypeScript version 4.5:

    [...] it would be nice to avoid two import statements for the same module. That’s part of why TypeScript 4.5 allows a type modifier on individual named imports, so that you can mix and match as needed.

    ...whereas your package.json requires:

    "typescript": "4.4.3"
    

    So, if your project allows it, you should be good by simply updating your typescript devDependency to version 4.5+.