webpack-babel-env-deps
raw JSON → 1.6.4 verified Sat Apr 25 auth: no javascript
A webpack helper to identify which npm dependencies need Babel transpilation by comparing their package.json engines and module fields against your project's Node.js targets. Version 1.6.4 is current; stable with minor releases. Key differentiator: automates the tedious manual process of checking each dependency's engine compatibility for transpilation decisions, integrating with @babel/preset-env to avoid over-transpiling or missing required transforms.
Common errors
error Cannot find module '@babel/preset-env' ↓
cause Missing peer dependency @babel/preset-env
fix
npm install @babel/preset-env@^7
error TypeError: findDependenciesToTranspile is not a function ↓
cause Importing incorrectly as default instead of named
fix
Use const { findDependenciesToTranspile } = require('webpack-babel-env-deps');
error Error: Options 'targets' is deprecated ↓
cause Using deprecated options from older version of package or @babel/preset-env
fix
Check documentation for current API; use 'packageContent' and 'dependencies' arguments
Warnings
gotcha Node.js >=6 required, may not work with older Node.js versions ↓
fix Upgrade Node.js to >=6 or use older version of this package
deprecated Use of engines field may cause false positives/negatives if dependencies don't specify engines ↓
fix Ensure all dependencies have accurate engines field; use module field as fallback
gotcha Default export may be mistaken for named export; import correctly ↓
fix Use default import or explicitly import named functions
gotcha Requires @babel/preset-env as peer dependency at version ^7 ↓
fix Install @babel/preset-env@^7 alongside this package
Install
npm install webpack-babel-env-deps yarn add webpack-babel-env-deps pnpm add webpack-babel-env-deps Imports
- findDependenciesToTranspile wrong
const findDependenciesToTranspile = require('webpack-babel-env-deps').findDependenciesToTranspilecorrectimport { findDependenciesToTranspile } from 'webpack-babel-env-deps' - default wrong
const webpackBabelEnvDeps = require('webpack-babel-env-deps').defaultcorrectimport webpackBabelEnvDeps from 'webpack-babel-env-deps' - addPlugins wrong
const addPlugins = require('webpack-babel-env-deps/addPlugins')correctimport { addPlugins } from 'webpack-babel-env-deps'
Quickstart
// webpack.config.js
const { findDependenciesToTranspile } = require('webpack-babel-env-deps');
module.exports = {
// ...
module: {
rules: [
{
test: /\.js$/,
exclude: filename => {
// Exclude node_modules except those that need transpilation
if (filename.indexOf('node_modules') === -1) return false;
return !findDependenciesToTranspile({
packageContent: { engines: { node: '>=6' } }, // your project's engines
dependencies: ['some-es6-pkg'], // list of dependency names
});
},
use: 'babel-loader',
},
],
},
};