question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught TypeError: Cannot read property 'config' of undefined

See original GitHub issue

Describe the bug A clear and concise description of what the bug is.

Screen Shot 2021-05-20 at 9 54 53 AM

To Reproduce

window.require (discussed below) is undefined. Is there something about this webpack config that would be problematic? How/where is window.require defined?

Webpack Config

{
  mode: 'development',
  entry: './src/client/index',
  output: {
    filename: '[name].js',
    libraryTarget: 'system',
    path: '/Users/pmikitsh/git/apps/packages/data-query/dist',
    uniqueName: 'data-query',
    devtoolNamespace: 'data-query',
    publicPath: 'http://0.0.0.0:9010/'
  },
  module: {
    rules: [
      {
        test: /\.(js|ts)x?$/,
        exclude: /node_modules/,
        use: {
          loader: '/Users/pmikitsh/git/apps/node_modules/babel-loader/lib/index.js'
        }
      },
      {
        test: /\.css$/i,
        include: [ /node_modules/, /src/ ],
        use: [
          {
            loader: '/Users/pmikitsh/git/apps/node_modules/style-loader/dist/cjs.js'
          },
          {
            loader: '/Users/pmikitsh/git/apps/node_modules/css-loader/dist/cjs.js',
            options: { modules: false }
          }
        ]
      },
      {
        test: /\.(bmp|png|svg|jpg|jpeg|gif|webp)$/i,
        exclude: /node_modules/,
        type: 'asset/resource'
      },
      {
        test: /\.html$/i,
        exclude: /node_modules/,
        type: 'asset/source'
      },
      { test: /\.ttf$/, use: [ 'file-loader' ] }
    ]
  },
  devtool: 'source-map',
  devServer: {
    compress: true,
    historyApiFallback: true,
    headers: { 'Access-Control-Allow-Origin': '*' },
    firewall: false,
    client: { host: 'localhost' },
    port: 9010,
    https: false
  },
  externals: [],
  plugins: [
    BundleAnalyzerPlugin {
      opts: {
        analyzerMode: 'disabled',
        analyzerHost: '127.0.0.1',
        reportFilename: null,
        reportTitle: [Function (anonymous)],
        defaultSizes: 'parsed',
        openAnalyzer: true,
        generateStatsFile: false,
        statsFilename: 'stats.json',
        statsOptions: null,
        excludeAssets: null,
        logLevel: 'info',
        startAnalyzer: true,
        analyzerPort: 8888
      },
      server: null,
      logger: Logger {
        activeLevels: Set(4) { 'info', 'warn', 'error', 'silent' }
      }
    },
    SystemJSPublicPathWebpackPlugin {
      options: {
        systemjsModuleName: '@platform-ui/data-query',
        rootDirectoryLevel: undefined
      }
    },
    HtmlWebpackPlugin { userOptions: {}, version: 5 },
    StandaloneSingleSpaPlugin {
      options: {
        isParcel: false,
        activeWhen: [ '/' ],
        importMap: { imports: {} },
        disabled: true,
        HtmlWebpackPlugin: [class HtmlWebpackPlugin] {
          version: 5,
          getHooks: [Function: getHtmlWebpackPluginHooks],
          createHtmlTagObject: [Function: createHtmlTagObject]
        },
        appOrParcelName: '@platform-ui/data-query'
      }
    },
    ForkTsCheckerWebpackPlugin {
      options: { typescript: { mode: 'write-references' } }
    }
  ],
  resolve: {
    extensions: [
      '.mjs',  '.js',
      '.jsx',  '.wasm',
      '.json', '.ts',
      '.tsx'
    ],
    fallback: {
      assert: '/Users/pmikitsh/git/apps/node_modules/assert/assert.js',
      buffer: '/Users/pmikitsh/git/apps/node_modules/buffer/index.js',
      child_process: false,
      cluster: false,
      console: '/Users/pmikitsh/git/apps/node_modules/console-browserify/index.js',
      constants: '/Users/pmikitsh/git/apps/node_modules/constants-browserify/constants.json',
      crypto: '/Users/pmikitsh/git/apps/node_modules/crypto-browserify/index.js',
      dgram: false,
      dns: false,
      domain: '/Users/pmikitsh/git/apps/node_modules/domain-browser/source/index.js',
      events: '/Users/pmikitsh/git/apps/node_modules/events/events.js',
      fs: false,
      http: '/Users/pmikitsh/git/apps/node_modules/stream-http/index.js',
      https: '/Users/pmikitsh/git/apps/node_modules/https-browserify/index.js',
      module: false,
      net: false,
      os: '/Users/pmikitsh/git/apps/node_modules/os-browserify/browser.js',
      path: '/Users/pmikitsh/git/apps/node_modules/path-browserify/index.js',
      punycode: '/Users/pmikitsh/git/apps/node_modules/node-libs-browser/node_modules/punycode/punycode.js',
      process: '/Users/pmikitsh/git/apps/node_modules/process/browser.js',
      querystring: '/Users/pmikitsh/git/apps/node_modules/querystring-es3/index.js',
      readline: false,
      repl: false,
      stream: '/Users/pmikitsh/git/apps/node_modules/stream-browserify/index.js',
      _stream_duplex: '/Users/pmikitsh/git/apps/node_modules/readable-stream/duplex.js',
      _stream_passthrough: '/Users/pmikitsh/git/apps/node_modules/readable-stream/passthrough.js',
      _stream_readable: '/Users/pmikitsh/git/apps/node_modules/readable-stream/readable.js',
      _stream_transform: '/Users/pmikitsh/git/apps/node_modules/readable-stream/transform.js',
      _stream_writable: '/Users/pmikitsh/git/apps/node_modules/readable-stream/writable.js',
      string_decoder: '/Users/pmikitsh/git/apps/node_modules/string_decoder/lib/string_decoder.js',
      sys: '/Users/pmikitsh/git/apps/node_modules/node-libs-browser/node_modules/util/util.js',
      timers: '/Users/pmikitsh/git/apps/node_modules/timers-browserify/main.js',
      tls: false,
      tty: '/Users/pmikitsh/git/apps/node_modules/tty-browserify/index.js',
      url: '/Users/pmikitsh/git/apps/node_modules/url/url.js',
      util: '/Users/pmikitsh/git/apps/node_modules/node-libs-browser/node_modules/util/util.js',
      vm: '/Users/pmikitsh/git/apps/node_modules/vm-browserify/index.js',
      zlib: '/Users/pmikitsh/git/apps/node_modules/browserify-zlib/lib/index.js'
    }
  },
  stats: 'errors-warnings'
}

Expected behavior A clear and concise description of what you expected to happen.

No runtime error is thrown

Screenshots If applicable, add screenshots to help to explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS] Mac
  • Browser [e.g. chrome, safari] Chrome
  • Version [e.g. 22] Latest

Additional context Add any other context about the problem here.

In file node_modules/@monaco-editor/loader/lib/es/loader/index.js:

function configureLoader() {
  var state = getState(function (_ref3) {
    var config = _ref3.config,
        resolve = _ref3.resolve,
        reject = _ref3.reject;
    return {
      config: config,
      resolve: resolve,
      reject: reject
    };
  });
  var require = window.require;

  require.config(state.config);

I am observing that window.require is undefined.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
suren-atoyancommented, May 23, 2021

@petermikitsh I see, the problem is that systemJS define function is conflicting with monaco-loader define function. To avoid it one option is doing something like this. So, try this instead of index.js of your example:

import React from "react";
import ReactDOM from "react-dom";
import Editor from "@monaco-editor/react";

const systemJsDefine = window.define;
window.define = null;

function App() {
  function handleEditorMount() {
    window.define = systemJsDefine;
  }

  return (
    <Editor
      height="90vh"
      onMount={handleEditorMount}
    />
  )
}

const mount = document.createElement("div");
document.body.appendChild(mount);

ReactDOM.render(<App />, mount);

Check the monaco-loader source. Search for if (typeof AMDLoader.global.define !== 'function' || !AMDLoader.global.define.amd) {. The existing global.define doesn’t let it to initialize the monaco-loader

1reaction
joeldenningcommented, May 27, 2021

I help maintain SystemJS - here’s an issue where I discussed a similar problem with other systemjs users. Deleting window.define and reinstating it later is a good option, or deleting the entire amd.js extra if you can.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'config' of undefined ... - GitHub
The error occurs when a null/undefined value is passed to the tailwindcss function. 2
Read more >
Cannot read property 'config' of null TypeError - Stack Overflow
This error occurs when angular cannot find .angular-cli.json file (Do note there is a dot in the file name). Usually it is a...
Read more >
Cannot read property 'config' of undefined
I get this error just randomly: Uncaught Error in $A.getCallback() [Cannot read property ' ...
Read more >
TypeError: Cannot read property 'config' of null at Class.run
Try the following steps remove the `node_modules` folder. Delete the yarn.lock is you have one. then `npm Install` or the yarn variant. Regards....
Read more >
typeerror: cannot read properties of undefined (reading 'config')
Here's an example of a JavaScript TypeError: Cannot read property of undefined thrown when a property is attempted to be read on an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found