-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
import-order
: Relative imports now listed first when using Yarn 2 PnP
#2164
Comments
This sounds unsurprising, since pnp probably resolves everything to the same kind of file. @arcanis? It’s possible that when using pnp, a custom import resolver will be needed, since it’s not using node resolution. |
I just listed external modules in pathGroups, though cumbersome, to make them recognized as external modules. ...
rules: {
'import/order': [
'warn',
{
'newlines-between': 'always',
'pathGroups': [
{
pattern: 'react',
group: 'external',
},
{
pattern: 'react-dom',
group: 'external',
},
],
'alphabetize': {
order: 'asc',
caseInsensitive: true,
},
},
],
},
... |
I have the same bug!
sibling imports are placed above my "internal" group. With version 2.23.4, there is no problem! For now a workaround is to downgrade to this version. |
* docs: add github issue and pr template * add `.github/ISSUE_TEMPLATE/feature-request.md` * add `.github/pull_request_template.md` Refs: https://github.com/younho9/dotfiles/tree/main/.github * chore: yarn workspace init * chore: setup commitlint * commitlint 설정 * husky 설정 Refs: - https://github.com/conventional-changelog/commitlint#getting-started - https://typicode.github.io/husky * chore: setup prettier * chore: setup eslint * chore(`eslint`): modify eslint-plugin-import rules - `import/no-unresolved` 활성화 - `import/order` - 에러 레벨 `warn`으로 낮춤 - `pathGroupsExcludedImportTypes` 옵션 제거 (해당 옵션 이해하지 못함) - PnP mode에서, 외부 모듈이 제대로 정렬되지 않는 이슈 있음 - `pathGroups`에 외부 모듈을 직접 나열하면 해결 가능 See: - import-js/eslint-plugin-import#2164 * docs(`.github`): update issue templates * chore: setup babel build process for modules * chore: setup babel build process See: - https://krasimirtsonev.com/blog/article/transpile-to-esm-with-babel - https://ui.toast.com/weekly-pick/ko_20180716 * chore: add license * chore: modify monorepo setup - Update .gitignore - Add .gitattributes - Add dist and tsconfig.json of root to .prettierignore - Add yarn berry workspace-tool plugin * feat(`prettier-config`): add prettier config * feat(`prettier-config`): change to module.exports * feat(`prettier-config`): modify babel config * chore: add prettier-config to root dev deps * chore(`release`): change git commit message * chore: install prettier config * chore(`prettier-config`): add build cycle * chore(`monorepo`): change name and add version & repo * chore(`lerna`): configure changelog preset
After editing the eslint plugin settings, I don't see this error anymore with Yarn v3.1.1 and eslint-plugin-import@2.25.4. Important (from the README):
When adding |
For me the fix was
Basically:
|
in my case, it works for me // .eslintrc.js
const getExternals = () => {
const getPackageJson = () =>
require(path.resolve(process.cwd(), 'package.json'));
const { dependencies, peerDependencies, devDependencies } = getPackageJson();
return Object.keys({
...dependencies,
...peerDependencies,
...devDependencies,
});
};
// ...
'import/order': [
'error',
{
groups: [
['builtin', 'external'],
['internal', 'parent', 'sibling'],
],
pathGroups: [
...getExternals().map((name) => ({
pattern: `${name}`,
group: 'external',
})),
...getExternals().map((name) => ({
pattern: `${name}/**`,
group: 'external',
})),
// ... |
maybe this is more proper way to sort external deps // .eslintrc.js
// ...
settings: {
'import/external-module-folders': ['.yarn'],
// ... thx @dlindenkreuz :) |
Minimal reproduction: https://github.com/ryb73/eslint-import-order-repro
I have the following imports:
With
.eslintrc.js
:I expect to get the following warning:
Instead I get:
It appears to happen when using Yarn 2's PNP linker.
The text was updated successfully, but these errors were encountered: