Skip to content

__MK_GLOBAL__ is not defined on adding css. #8

Description

@Shuraken007

Hi there.
I added rm_style.css to userscript.
With default rules:

       rules: [
         {
            exclude: /(node_modules)/,
            test: /\.css$/i,
            use: ['style-loader', 'css-loader'],
         },
      ],

Webpack processed this, added text from file.
Also it inserted this block to compiled file

!*** ./node_modules/webpack-monkey/lib/node/deps/style-loader-insertStyleElement.js ***!
...
module.exports = function () {
  return __MK_GLOBAL__.styleLoaderInsertStyleElement.apply(null, arguments)
}
...

I got error Uncaught (in promise) ReferenceError: __MK_GLOBAL__ is not defined

Image

I grepped packages - it's your package constant

./webpack-monkey/lib/client/client.js:window.__MK_GLOBAL__ = {
./webpack-monkey/lib/client/client.js:const { userscripts } = __MK_GLOBAL__;
./webpack-monkey/lib/client/client.js:    if (__MK_GLOBAL__.debug) {
./webpack-monkey/lib/shared/constants.js:exports.VAR_MK_GLOBAL = "__MK_GLOBAL__";
./webpack-monkey/lib/node/deps/style-loader-insertStyleElement.js:  return __MK_GLOBAL__.styleLoaderInsertStyleElement.apply(null, arguments)
./webpack-monkey/lib/node/deps/mini-css-extract-hmr.js:  return __MK_GLOBAL__.miniCssExtractHmr.apply(null, arguments)

I googled and founded only one mention of this problem.
https://gitlab.com/Pyztug-9mafda-tifxac/voice-over-translation/-/blob/e7a357a5dd7f5060bbc7359d899b62df2040efcb/webpack.config.js

So I added same manipulations to redefine constant manually.
Everything works. Browser loaded and applied styles.

const webpack = require("webpack")
const { styleLoaderInsertStyleElement } = require("webpack-monkey/lib/client/css.js")
//------------------------------------------------------------

   plugins: [
      new webpack.DefinePlugin({
         __MK_GLOBAL__: {
            styleLoaderInsertStyleElement,
         },
      }),
   ],

I'm using Tampermonkey v5.3.3 from Google Chrome Store
https://chromewebstore.google.com/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo
Last chrome version: 133.0.6943.142
I added script via 'import as url' (no dev-server).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions