{"id":14628,"library":"import-sort-parser-babylon","title":"Import Sort Babylon Parser","description":"import-sort-parser-babylon is a specialized parser plugin designed for the `import-sort` ecosystem, enabling the sorting of ECMAScript (ES2015+) imports in JavaScript and TypeScript files. Currently at version 6.0.0, this package integrates with the primary `import-sort` library, which is generally used in conjunction with `import-sort-config` and a chosen sorting style (e.g., `import-sort-style-eslint`). It leverages the capabilities of the Babel parser (formerly known as Babylon) to analyze and manipulate import declarations, offering robust support for modern JavaScript syntax, JSX, and TypeScript features. The `import-sort` project, of which this parser is a component, appears to maintain an active development cadence, providing tools for CLI usage, editor integrations, and programmatic sorting. Its key differentiator lies in its use of the battle-tested Babel parsing engine, ensuring broad compatibility with various language features and proposals.","status":"active","version":"6.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/renke/import-sort","tags":["javascript","typescript"],"install":[{"cmd":"npm install import-sort-parser-babylon","lang":"bash","label":"npm"},{"cmd":"yarn add import-sort-parser-babylon","lang":"bash","label":"yarn"},{"cmd":"pnpm add import-sort-parser-babylon","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package implements the core parser interface required by the import-sort ecosystem.","package":"import-sort-parser","optional":false},{"reason":"Provides the underlying JavaScript/TypeScript parsing capabilities, formerly known as 'babylon'. This package is built on top of it.","package":"@babel/parser","optional":false}],"imports":[{"note":"The primary export is typically a default parser configuration or function, consumed by the 'import-sort' core. While modern configurations prefer ESM, CommonJS `require` might still function in older Node.js environments if the package provides dual exports.","wrong":"const babylonParser = require('import-sort-parser-babylon');","symbol":"default","correct":"import babylonParser from 'import-sort-parser-babylon';"},{"note":"This package ships TypeScript types. The type definition for the parser interface is useful for custom integrations or understanding the expected structure.","symbol":"ImportSortParser","correct":"import type { ImportSortParser } from 'import-sort-parser-babylon';"}],"quickstart":{"code":"{\n  \"importSort\": {\n    \"language\": \"javascript\",\n    \".js, .jsx, .ts, .tsx\": {\n      \"parser\": \"babylon\",\n      \"style\": \"eslint\",\n      \"options\": {\n        \"parserOptions\": {\n          \"ecmaVersion\": \"latest\",\n          \"sourceType\": \"module\",\n          \"plugins\": [\n            \"jsx\",\n            \"typescript\",\n            \"classProperties\",\n            \"decorators-legacy\",\n            \"dynamicImport\"\n          ]\n        }\n      }\n    }\n  }\n}","lang":"json","description":"This configuration snippet for `.importsortrc` or `package.json` demonstrates how to instruct `import-sort` to use the `babylon` parser for various file types and configure Babel parser options for modern syntax support."},"warnings":[{"fix":"Ensure your Babel configuration (if separate) is updated to use `@babel/parser`. If passing `parserOptions` directly to `import-sort`, ensure plugin names align with `@babel/parser`'s expected values. Review `prettier-plugin-sort-imports` migration guides for common parser option changes.","message":"The underlying parser 'babylon' was renamed to '@babel/parser'. While 'import-sort-parser-babylon' might abstract this, direct usage or advanced configuration might require referencing '@babel/parser' features or plugins.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Always explicitly define necessary Babel plugins within the `parserOptions.plugins` array in your `.importsortrc` or `package.json` configuration, matching the features used in your codebase. Refer to `@babel/parser` documentation for available plugins.","message":"Incorrect or missing Babel parser plugins in your `import-sort` configuration can lead to parsing errors for modern JavaScript or TypeScript syntax (e.g., decorators, class properties).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Disable or remove competing import sorting rules in ESLint or Prettier when `import-sort` is active, allowing `import-sort` to be the single source of truth for import ordering.","message":"Conflicting import sorting rules from other tools like ESLint (`sort-imports`) or Prettier plugins can lead to formatting churn or unexpected behavior.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Verify `import-sort` and its parsers are correctly installed and resolvable by your toolchain. Check for any specific setup instructions or known issues related to your package manager (like pnpm) or other formatting tools in the `import-sort` or `prettier-plugin-sort-imports` repositories.","message":"When using `import-sort` within a broader toolchain (e.g., with Prettier v3.x or pnpm), ensure compatibility and correct plugin resolution, as some users have reported issues with specific package managers or tool versions.","severity":"gotcha","affected_versions":">=6.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Add the required Babel parser plugin (e.g., `jsx`, `typescript`, `decorators-legacy`) to the `parserOptions.plugins` array in your `importSort` configuration within `package.json` or `.importsortrc`.","cause":"The Babel parser used by `import-sort-parser-babylon` did not recognize a specific language feature (e.g., new syntax, TypeScript, JSX) because the corresponding plugin was not enabled in the configuration.","error":"SyntaxError: Unexpected token (X:Y)"},{"fix":"Ensure `import-sort-parser-babylon` is correctly installed and listed in your project dependencies. Verify your `importSort` configuration specifies `'babylon'` as the parser name, and restart any IDE extensions or CLI processes to reload the configuration.","cause":"The `import-sort` core or integration could not find or correctly load the parser function from `import-sort-parser-babylon`, possibly due to incorrect module resolution or a corrupted installation.","error":"parser.parseImports is not a function"},{"fix":"Double-check that `import-sort-parser-babylon` is installed in your project and that your `importSort` configuration correctly specifies `parser: 'babylon'` (or similar, depending on the exact `import-sort` configuration structure).","cause":"The `import-sort` tool itself (or its CLI/IDE integration) failed to locate the `import-sort-parser-babylon` package, often due to an incorrect package name in the configuration or an incomplete installation.","error":"Configuration error: Unknown parser 'babylon'"}],"ecosystem":"npm"}