Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: require file extension '.js or .svg' (n/file-extension-in-import) #11

Closed
mrtnzlml opened this issue Feb 27, 2022 · 1 comment
Closed

Comments

@mrtnzlml
Copy link

Hi, there is a breaking change between versions 14 and 15 and I would like to report/discuss whether it's intentional or not (and how to fix it).

Basically, rule n/file-extension-in-import started reporting the following errors:

error: require file extension '.js or .svg' (n/file-extension-in-import) at src/abacus-kochka/src/LanguageSwitch.js:9:20:
   7 | 
   8 | import FlagMX from './design/svg/generated/flags/mx';
>  9 | import FlagUS from './design/svg/generated/flags/us';
     |                    ^
  10 | import useViewerContext from './hooks/useViewerContext';
  11 | 
  12 | export default function LanguageSwitch(): React.Node {

The thing is that everything works as it did before. Moreover, other imports are not problematic. I think it happens only when there are more files with the same name. For example in this case the content of the folder I am trying to import from is:

├── mx.js
├── mx.svg
├── us.js
└── us.svg

Is it intentional behavior? How should it be fixed? I could of course add the extensions like so:

import FlagMX from './design/svg/generated/flags/mx.js';
import FlagUS from './design/svg/generated/flags/us.js';

However, that goes against import/extensions because we disallow extensions. What is the motivation behind this change and what is the correct behavior?

@aladdin-add
Copy link

yes, it's expected(changelog).

the main reason is node.js esm requires it. see the docs: https://nodejs.org/api/esm.html#mandatory-file-extensions

kodiakhq bot pushed a commit to adeira/universe that referenced this issue Feb 28, 2022
adeira-github-bot pushed a commit to mrtnzlml-archive/kochka.com.mx that referenced this issue Feb 28, 2022
This fixes broken master, again.

See: eslint-community/eslint-plugin-n#11

adeira-source-id: d63535b707c43dc0b4749b51f14803b7ddcc88ea
adeira-github-bot pushed a commit to adeira/abacus-kochka that referenced this issue Feb 28, 2022
This fixes broken master, again.

See: eslint-community/eslint-plugin-n#11

adeira-source-id: d63535b707c43dc0b4749b51f14803b7ddcc88ea
adeira-github-bot pushed a commit to adeira/relay-example that referenced this issue Feb 28, 2022
This fixes broken master, again.

See: eslint-community/eslint-plugin-n#11

adeira-source-id: d63535b707c43dc0b4749b51f14803b7ddcc88ea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants