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.

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.
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.
npm install babel-plugin-import-remove-resource-query
yarn add babel-plugin-import-remove-resource-query
pnpm add babel-plugin-import-remove-resource-query

Shows usage in Babel config and transformation of imports/require removing query strings.

// 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');