babel-plugin-import-remove-resource-query
raw JSON → 1.0.0 verified Sat Apr 25 auth: no javascript
Babel plugin that strips resource query parameters (e.g., ?query) from import/require statements during compilation. Version 1.0.0, no further releases. Designed to work around Jest's lack of support for webpack resource queries in imports. Simple, single-purpose plugin with no configuration needed.
Common errors
error Error: Cannot find module 'babel-plugin-import-remove-resource-query' ↓
cause Plugin not installed or not in node_modules.
fix
Run 'npm install babel-plugin-import-remove-resource-query --save-dev' or 'yarn add --dev babel-plugin-import-remove-resource-query'.
error require() of ES Module not supported ↓
cause Using ESM import in babel.config.js (e.g., .mjs) while plugin is CJS.
fix
Use require() in babel config or rename file to .js and use module.exports.
Warnings
gotcha Plugin strips ALL query parameters, including legitimate ones like ?inline for CSS. ↓
fix If needed, use a different approach or customize the plugin (not currently supported).
gotcha No version updates since initial release; may not support newer Babel versions. ↓
fix Test with your Babel version; consider alternative if incompatibility arises.
Install
npm install babel-plugin-import-remove-resource-query yarn add babel-plugin-import-remove-resource-query pnpm add babel-plugin-import-remove-resource-query Imports
- default wrong
import plugin from 'babel-plugin-import-remove-resource-query'correctmodule.exports = require('babel-plugin-import-remove-resource-query') - plugins wrong
plugins: [['babel-plugin-import-remove-resource-query', { /* options */ }]]correctplugins: ['babel-plugin-import-remove-resource-query'] - module syntax (no import needed)
Add to .babelrc or babel.config.js as a plugin string.
Quickstart
// babel.config.js
module.exports = {
presets: ['@babel/preset-env'],
plugins: ['babel-plugin-import-remove-resource-query']
};
// input.js
import 'path/to/file?resourceQuery';
import foo from 'path/to/file?query';
require('path/to/file?resourceQuery');
// output.js
import 'path/to/file';
import foo from 'path/to/file';
require('path/to/file');