{"id":20772,"library":"webpack-global-object-x","title":"webpack-global-object-x","description":"Utility to provide the correct global object for webpack's globalObject configuration, supporting Node.js, browsers, and Web Workers. Current stable version is 1.0.1, released with no updates since 2018. It returns a function that, when called, yields the global object (`global`, `self`, or `this`). Lightweight (no dependencies) and intended for use in webpack configuration to set `output.globalObject` for UMD bundles. Differentiators: simple, focused, and independent of any runtime environment detection library.","status":"maintenance","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/Xotic750/webpack-global-object-x","tags":["javascript","webpack","globalObject","module","nodejs","browser"],"install":[{"cmd":"npm install webpack-global-object-x","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-global-object-x","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-global-object-x","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package uses CommonJS and does not provide ESM exports. Use require() or enable CJS interop in your bundler.","wrong":"import { globalObject } from 'webpack-global-object-x';","symbol":"globalObject","correct":"const globalObject = require('webpack-global-object-x');"},{"note":"If using a bundler that can import CommonJS as default, you can use default import. The named export does not exist.","wrong":"import { globalObject } from 'webpack-global-object-x';","symbol":"default","correct":"import globalObject from 'webpack-global-object-x';"},{"note":"The module exports a function that returns the global object. You must call it to get the value.","wrong":"const obj = require('webpack-global-object-x'); // returns a function, not the object","symbol":"function","correct":"const globalObject = require('webpack-global-object-x');\nconst obj = globalObject();"}],"quickstart":{"code":"// webpack.config.js\nconst globalObject = require('webpack-global-object-x');\n\nmodule.exports = {\n  output: {\n    globalObject: '(' + globalObject.toString() + '())',\n    library: 'MyLib',\n    libraryTarget: 'umd'\n  }\n};","lang":"javascript","description":"Shows how to use webpack-global-object-x in a webpack config to set the globalObject option for UMD bundles."},"warnings":[{"fix":"Use globalObject() to obtain the actual global object.","message":"The module exports a function, not the global object itself. You must call it to get the global object.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use require() or enable interop (e.g., createRequire/import from CommonJS).","message":"No ESM export; cannot be imported with named import syntax in Node.js without CJS interop.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider alternatives like using built-in globalThis (available in Node 12+, modern browsers) or the 'global' npm module.","message":"The package is not actively maintained; last release was in 2018. May not support future webpack versions or newer JS environments.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install webpack-global-object-x --save-dev","cause":"Package not installed or typo in package name.","error":"Error: Cannot find module 'webpack-global-object-x'"},{"fix":"Change code to: const globalObject = require('webpack-global-object-x'); const obj = globalObject();","cause":"Using the imported function without calling it.","error":"Uncaught TypeError: globalObject is not a function"},{"fix":"Use a bundler that supports CommonJS or pre-compile the package with your build tool.","cause":"Attempting to import in a browser environment where require is not available.","error":"Module not found: Error: Can't resolve 'webpack-global-object-x' in ..."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}