Skip to content
Advertisement

Must use import to load ES Module .eslintrc.js

I am trying to fix this problem for hours. I’ve read nearly every post about this, but still, I came to no solution.

I am trying to deploy a firebase-function with the “https got-library” dependency, but no matter what I do, nothing works. I am not the best with node-js or typescript (usually a kotlin frontend-dev), so I have no clue what the error wants from me.

Tsconfig.json

JavaScript

.eslintrc.js

JavaScript

package.json

JavaScript

Error

JavaScript

Function I want to deploy

JavaScript

Edit

Changing .eslintrc.js to .eslintrc.cjs solves this problem, but then I get the following error:

JavaScript

Edit 2

Removing “type”:”module” then gives me this error again:

JavaScript

Edit 3

Following changes have been made:

  • Change “module” : “commonjs” -> “module”: “es6”
  • Change “target” : “es2017” -> “target”: “es6”
  • Add “moduleResolution”: “node” in tsconfig.js (inside compileroptions).
  • Add “type”:”module” to package.json

Now I am getting the following error:

JavaScript

Here is the code (constants.f.ts)

export const constants = { /** * Default firebase-functions region */ region: “europe-west1”, } as const;

Edit 4

Looks like I’ve fixed all my problems. When using “module”: “es6”, one has to import its module like this:

JavaScript

and not like this:

JavaScript

The ending “.js” is important

Advertisement

Answer

Quoting from the ESLint documentation:

use .eslintrc.cjs when running ESLint in JavaScript packages that specify "type":"module" in their package.json. Note that ESLint does not support ESM configuration at this time.

Since you have "type": "module" in your package.json file, you should be fine by renaming “.eslintrc.js” to “.eslintrc.cjs”.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement