doemsche doemsche -3 years ago 170
React JSX Question

Render json is not defined in React

Can anybody explain to me the following scenario in a react-js context:
I work with webpack and use the presets "babel-preset-env" & "react".

On top of a file I import a config.json which I try to inspect with the developer tools and a debugger-statement.

The console.log logs an array of objects as expected. If I enter the developer-tools js-console and enter CONFIG I get an Uncaught ReferenceError: CONFIG is not defined.

import React, { Component } from 'react';
import CONFIG from './config.json';

class MyComponent extends Component{
//this statement logs as expected

// the debugger stops execution, but when I enter CONFIG in the
// dev-tools Console I get the error: Uncaught ReferenceError:
// CONFIG is not defined

Any help is much appreciated.

Answer Source

CONFIG is defined inside the module you are writing. It's not a real global variable, it's only "global" inside that module (i.e. that file).

If you really want to make it globally available in browser, try adding window.CONFIG = CONFIG.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download