sindresorhus / p-queue

Promise queue with concurrency control
MIT License
3.45k stars 185 forks source link

Must use import to load ES Module #151

Closed randal923 closed 3 years ago

randal923 commented 3 years ago

I am getting this error but I am using import.

Node version 14.15.4

Code:

import axios from 'axios'
import fs from 'fs'
import PQueue from 'p-queue'

async function getApplicants (): Promise<void> {
  const queue = new PQueue({ concurrency: 4 })

  for (let i = Number(page) + 1; i < Infinity; i++) {
   "..."
    const respose = await queue.add(async () => await axios.get('url'))
   "..."
  }

  await queue.onIdle()

 "do stuff..."
}

export default getApplicants

package.json:

{
  "name": "api",
  "version": "0.0.1",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "dev": "nodemon src/server.ts",
    "debug": "nodemon -L --watch ./dist --inspect=0.0.0.0:9222 --nolazy ./dist/main/server.js",
    "start": "NODE_ENV=production pm2 start dist/server.js --name='api'",
    "build": "rimraf dist && tsc -p tsconfig-build.json",
    "test": "jest --passWithNoTests --silent --noStackTrace --runInBand",
    "test:verbose": "jest --passWithNoTests --runInBand",
    "test:unit": "yarn test --watch -c jest-unit-config.js",
    "test:integration": "yarn test --watch -c jest-integration-config.js",
    "test:staged": "yarn test --findRelatedTests",
    "test:ci": "yarn test --coverage"
  },
  "devDependencies": {
  },
  "dependencies": {

  },
  "resolutions": {
    "@types/express/@types/express-serve-static-core": "4.17.20"
  },
  "_moduleAliases": {
    "@": "src"
  }
}

tsconfig:

{
  "compilerOptions": {
    "outDir": "dist",
    "module": "commonjs",
    "target": "es2019",
    "esModuleInterop": true,
    "sourceMap": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "resolveJsonModule": true,
    "baseUrl": "./src",
    "paths": {
      "@/*": [
        "*"
      ]
    }
  },
  "include": [
    "src"
  ],
  "exclude": []
}

20210612062829605

sindresorhus commented 3 years ago

Duplicate of #151

balthazar commented 3 years ago

I think you meant #143 😄