sindresorhus / tempy

Get a random temporary file or directory path
MIT License
423 stars 26 forks source link

Import issue in Cypress project #42

Closed knyga closed 2 years ago

knyga commented 2 years ago

Problem:

/Users/oleksandrknyga/www/shaman/shaman-regression-scanner/node_modules/tempy/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import fs from 'node:fs';
                                                                                             ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      1 | import { validate as uuidValidate } from 'uuid'
    > 2 | import { temporaryFile } from 'tempy'
        | ^
      3 | import { Reporter } from '../index'

Package.json:

{
  "name": "...",
  "version": "...",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "test": "jest",
    "test-watch": "jest --watch",
    "cy:open": "cypress open",
    "cy:run": "cypress run --browser chrome --headless",
    "e2e-mocha": "npx cypress run --spec 'path_to_file' --browser chrome",
    "lint": "eslint . --ext .ts",
    "lint-fix": "eslint . --ext .ts --fix"
  },
  "dependencies": {
    "@aws-sdk/client-lambda": "^3.100.0",
    "@faker-js/faker": "^6.3.1",
    "axios": "^0.27.2",
    "csv": "^6.1.0",
    "cypress": "^10.0.1",
    "mochawesome": "^7.1.3",
    "typescript": "^4.7.2",
    "uuid": "^8.3.2"
  },
  "devDependencies": {
    "@aws-sdk/types": "^3.110.0",
    "@types/chai": "^4.1.7",
    "@types/jest": "26.0.22",
    "@types/mocha": "^8.0.0",
    "@types/node": "^17.0.42",
    "@types/uuid": "^8.3.4",
    "@typescript-eslint/eslint-plugin": "^5.27.1",
    "@typescript-eslint/parser": "^5.27.1",
    "aws-sdk-client-mock": "^1.0.0",
    "eslint": "^8.17.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-cypress": "^2.12.1",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-jsx-a11y": "^6.5.1",
    "jest": "26.6.3",
    "tempy": "^3.0.0",
    "ts-jest": "26.5.4"
  },
  "engines": {
    "npm": ">=7.0.0",
    "node": ">=16.0.0"
  }
}

I tried to use tempy for jest tests on typescript, but import fails.

sindresorhus commented 2 years ago

https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c