-1

I have a project based on create react-app, and it seems since an update of the yup dependency, it stopped launching error on invalid import.

The error "module filename has no exported member X", which used to be launched by react-scripts build, as well as by npm start has completely disappeared, though my IDE still finds such error.

react-scripts build and npm start will still launch an error if I try to use the unexisting import as a variable, but not if I try to use it as a type.

I tried looking at i.e this question or this one, or others similar questions, but none was like my case (i.e, the files giving problems DO have import, and the commit introducing the bug was litterally changing just the yup dependency in package.json, and changing package-lock.json accordingly. I also tried updating my @typescript-eslint/no-unused-vars rules to error, but it gave me too many errors, and I have no guarantee it'll catch any unexisting type exported and used as type)

In case it helps, here is my tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "src",
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react",
    "noFallthroughCasesInSwitch": true
  },
  "include": [
    "src"
  ]
}

and my .eslintrc.json

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "tsconfigRootDir": ".",
    "project": [
      "./tsconfig.json"
    ]
  },
  "extends": [
    "react-app",
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended"
  ],
  "plugins": [
    "filenames"
  ],
  "rules": {
    //- https://palantir.github.io/tslint/rules/no-null-undefined-union/ should be added once a typescript-eslint equivalent exists
    "@typescript-eslint/explicit-function-return-type": 0,
    "@typescript-eslint/no-explicit-any": 0,
    // as per https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md, we must disable the base rule to prefer the typescript one
    "no-unused-vars": 0,
    "filenames/match-exported": 1,
    "@typescript-eslint/prefer-as-const": 1,
    "@typescript-eslint/ban-types": 1,
    "@typescript-eslint/no-unnecessary-type-assertion": 1,
    "@typescript-eslint/strict-boolean-expressions": [
      1,
      {
        "allowNullableString": true,
        "allowNullableObject": true,
        "allowNullableBoolean": true,
        "allowNumber": false,
        "allowAny": true
        // we use lodash, better allow these any
      }
    ],
    "@typescript-eslint/no-unused-vars": 1,
    "no-return-await": 2,
    "curly": 2,
    "@typescript-eslint/no-inferrable-types": [
      2,
      {
        "ignoreParameters": true
      }
    ]
  }
}

Thank you for any help.

Jonathan Simonney
  • 585
  • 1
  • 11
  • 25
  • I’m voting to close this question because the author added an answer to his own question, seconds after asking the question. Then he deleted his own answer. This smells like an attempt to generate upvotes. – pascalpuetz Sep 21 '21 at 17:11
  • I thought I had a solution, then realised it didn't work, which is why I deleted it. I can promise you I don't want to generate upvotes at all, but am just desperate for fixing a very annoying bug, which I tried searching for solutions to no avail. – Jonathan Simonney Sep 21 '21 at 17:12
  • You added that answer right after, so you had the answer prepared beforehand. Realising that the answer is not correct was in a mere minute timeframe. This still sounds off to me. Leaving the vote. – pascalpuetz Sep 21 '21 at 17:13
  • I added the answer because it was in the linked questions proposed on the SO window you see before posting question. It seemed to work and I thought it did, as it generated indeed errors on my project. I then realised I didn't want exactly these errors (as there were too many, and, even if I haven't tested it properly yet, it probably still wouldn't get an exported type that was used in the file). – Jonathan Simonney Sep 21 '21 at 17:16
  • Sorry for not proof checking myself properly, ofc, but I'd really need help on this, and I tried to do my due diligence before posting. – Jonathan Simonney Sep 21 '21 at 17:16
  • Also, in case you have the right to see who upvoted and when, you'll see the linked answer in my deleted answer (https://stackoverflow.com/a/61555310/7059810) got an upvote from me some minutes before I posted my question and answer, which was because I found it (at the time) helpful for the problem I had to solve. – Jonathan Simonney Sep 21 '21 at 17:23
  • It's perfectly fine to answer your own question, just post it as an answer – Raz Luvaton Sep 21 '21 at 17:51
  • I did, using the answer your own question checkbox. But I realised it was false mere minutes after posting it so I deleted it. And since this gave me a close vote, and I really struggle with this problem, I try to justify why this was a behavior to find answer and not fish for upvotes – Jonathan Simonney Sep 21 '21 at 17:54

1 Answers1

0

So I ended up fixing this problem by reinstalling my dependencies with a more up to date version. I juste removed my node_module and my package-lock.json before running npm i. I know suppressing node_module and package-lock should have had no effect, but I preferred to be sure.

It made my project have all kind of new errors, but in the lot, there was my error for invalid import, so it was good for me.

Jonathan Simonney
  • 585
  • 1
  • 11
  • 25