Registry / web-framework / babel-file

babel-file

JSON →
library3.0.0jsnpmunverified

Utility to easily construct a Babel File object with code, AST, and path. v3.0.0 (latest) – stable, low maintenance. Provides a convenient wrapper around Babel core's File object, parsing code with Babel and returning the full file structure. Key differentiator: simplifies setup for Babel plugins/tools by handling File creation and error formatting. Requires Babel 7+ and babylon-options for parser options.

npm install babel-file
INSTALL
IMPORT
SIG · BABEL-FILE
B
babel-file
web-frameworkjavascriptv3.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import createFile from 'babel-file'
const createFile = require('babel-file')
ESM-only; no CommonJS export
default
import createFile from 'babel-file'
import { createFile } from 'babel-file'
Only default export; named export is not available
default
import createFile from 'babel-file'
import * as babelFile from 'babel-file'
Namespace import returns object with default property; use default import instead

Creates a Babel File object from source code, parsing with given options.

import createFile from 'babel-file'; import createBabylonOptions from 'babylon-options'; const code = 'const x = 1;'; const parserOpts = createBabylonOptions({ stage: 2 }); const file = createFile(code, { filename: 'example.js', parserOpts }); console.log(file.code); console.log(file.ast); console.log(file.path);
Debug
Known issues
breakingVersion 3.0.0 dropped support for Node.js < 10 and Babel < 7.
fix
Upgrade Node.js and Babel to required versions.
affects: <3.0.0
deprecatedbabylon-options package is deprecated; use Babel's parser options directly.
fix
Replace with inline parser options obj.
affects: >=3.0.0
gotchaFile object properties (code, ast, path) are not updated if you mutate the parsed code.
fix
Re-create File object after modifications.
affects: >=3.0.0
gotchaMissing or invalid parser options may cause crashes without informative error messages.
fix
Validate parser options same as in Babel core.
affects: >=3.0.0
Errors
Common errors & fixes
Cannot find module 'babel-file'
Package not installed or not in node_modules
fix
Run npm install babel-file
createFile is not a function
Tried named import instead of default import
fix
Use import createFile from 'babel-file'
The 'parserOpts' option is not supported
Passed incorrect options format
fix
Ensure parserOpts matches Babel's parser options
Cannot read property 'code' of undefined
File creation failed due to invalid code
fix
Check that code string is valid JavaScript
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
babylon-optionsoptionalUsed to create parser options in the example
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
babel-file — npm install babel-file · libregistry