Webpack supports Node APIs for features such as module systems, compile-time constants, etc., but most other bundlers do not support these APIs. For example:
process.env
in webpack, andimport.meta.env
in Vitemodule.exports
in webpack, andexport
in esbuildrequire.context
in webpack, andimport.meta.glob
in Vite
Instead, webpack can be configured or plugged to support more modern ES Module APIs.
This rule completes the following rules:
no-process-env
: It is deprecatedimport/no-commonjs
: It cannot detect cases such asrequire.resolve
This rule has an object option:
"allowProcessEnv"
(defaultfalse
) allowsprocess.env
"allowCommonJs"
(defaultfalse
) allowsmodule.exports
orexports.*
"allowRequire"
(defaultfalse
) allowsrequire
const version = process.env.VERSION
module.exports = foo
const { foo } = require('foo')
foo.source = require.resolve('bar')
const version = import.meta.env.VERSION
export default foo
import { foo } from 'foo'
/* eslint galaxy/esm-bundler: ["error", { "allowProcessEnv": true }] */
const version = process.env.VERSION