So I have been trying to get es6 imports to work for some while now. I have finally been able to load the core library. But I seem unable to import the inspector without running into window not defined errors. I am using babylonjs along with react and server side rendering for it.
plus the inspector bundle size is too huge that my webpack build goes into a stack error. I am using a custom webpack config for the server side rendering.
I dunno how to resolve this issue.
const path = require('path');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
const Dotenv = require('dotenv-webpack');
require('babel-polyfill');
const browserConfig = {
entry: {
'react-bundle': ['babel-polyfill', './new-visualisation-react/src/index.js'],
'react-product-pricer': ['babel-polyfill', './new-visualisation-react/src/components/productPricer/index.js'],
'react-product-item': ['babel-polyfill', './new-visualisation-react/src/pages/productItem/index.js'],
'react-curated-item': ['babel-polyfill', './new-visualisation-react/src/pages/curatedItem/index.js'],
},
output: {
path: path.resolve(__dirname, 'public', 'dist/js'),
filename: '[name].js',
publicPath: '/',
},
module: {
rules: [
{
test: /\.(js)$/,
loader: 'babel-loader',
include: path.join(__dirname, 'node_modules', '@babylonjs'),
exclude: [path.resolve(__dirname, './node_modules/')],
options: {
presets: ['@babel/preset-env'],
compact: false,
},
},
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
exclude: [path.resolve(__dirname, './node_modules/')],
options: {
presets: ['@babel/preset-react'],
},
},
{
test: /\.css?$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/,
loader: 'url-loader',
options: {
limit: 8192,
},
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.css'],
},
plugins: [
new webpack.DefinePlugin({
__isBrowser__: 'true',
}),
new Dotenv({
path: path.resolve(__dirname, './.env'),
}),
],
};
const serverConfig = {
entry: ['babel-polyfill', './app.js'],
target: 'node',
externals: [nodeExternals({
whitelist: ['bootstrap/dist/css/bootstrap.min.css', /^@babylonjs/],
})],
output: {
path: __dirname,
filename: 'server.js',
publicPath: '/',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-react', '@babel/preset-env'],
plugins: ['@babel/plugin-transform-modules-commonjs'],
compact: false,
},
},
{
test: /\.css?$/,
use: ['css-loader'],
},
{
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/,
loader: 'url-loader',
options: {
limit: 8192,
},
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.css'],
},
node: {
__dirname: true,
},
plugins: [
new webpack.DefinePlugin({
__isBrowser__: 'false',
}),
new Dotenv(),
],
};
module.exports = [browserConfig, serverConfig];
Error Log
/home/shailesh96/Denkali/denkali-website/server.js:330275
return window && document && document.all && !window.atob;
^
ReferenceError: window is not defined
at /home/shailesh96/Denkali/denkali-website/server.js:330275:11
at /home/shailesh96/Denkali/denkali-website/server.js:330264:56
at module.exports (/home/shailesh96/Denkali/denkali-website/server.js:330331:97)
at Object.componentsActionTabsActionTabsScss (/home/shailesh96/Denkali/denkali-website/server.js:332206:66)
at __webpack_require__ (/home/shailesh96/Denkali/denkali-website/server.js:279697:27)
at Module.componentsActionTabsActionTabsComponentTsx (/home/shailesh96/Denkali/denkali-website/server.js:332325:9)
at __webpack_require__ (/home/shailesh96/Denkali/denkali-website/server.js:279697:27)
at Module.inspectorTs (/home/shailesh96/Denkali/denkali-website/server.js:354751:87)
at __webpack_require__ (/home/shailesh96/Denkali/denkali-website/server.js:279697:27)
at Module.indexTs (/home/shailesh96/Denkali/denkali-website/server.js:354674:55)
at __webpack_require__ (/home/shailesh96/Denkali/denkali-website/server.js:279697:27)
at Module.<anonymous> (/home/shailesh96/Denkali/denkali-website/server.js:355317:53)
at Module.legacyLegacyTs (/home/shailesh96/Denkali/denkali-website/server.js:355335:12)
at __webpack_require__ (/home/shailesh96/Denkali/denkali-website/server.js:279697:27)
at ../../../../node_modules/@fortawesome/fontawesome-svg-core/index.es.js (/home/shailesh96/Denkali/denkali-website/server.js:279891:14)
at /home/shailesh96/Denkali/denkali-website/server.js:279893:6
at webpackUniversalModuleDefinition (/home/shailesh96/Denkali/denkali-website/server.js:279638:135)
at Object.<anonymous> (/home/shailesh96/Denkali/denkali-website/server.js:279642:3)
at Object../node_modules/@babylonjs/inspector/babylon.inspector.bundle.max.js (/home/shailesh96/Denkali/denkali-website/server.js:355525:30)
at __webpack_require__ (/home/shailesh96/Denkali/denkali-website/server.js:20:30)
at Object../new-visualisation-react/src/App.js (/home/shailesh96/Denkali/denkali-website/server.js:21909:1)
at __webpack_require__ (/home/shailesh96/Denkali/denkali-website/server.js:20:30)
at Object../controllers/static/staticController.js (/home/shailesh96/Denkali/denkali-website/server.js:5647:35)
at __webpack_require__ (/home/shailesh96/Denkali/denkali-website/server.js:20:30)
at Object../routes/static.js (/home/shailesh96/Denkali/denkali-website/server.js:382971:48)
at __webpack_require__ (/home/shailesh96/Denkali/denkali-website/server.js:20:30)
at Object../routes/index.js (/home/shailesh96/Denkali/denkali-website/server.js:382694:38)
at __webpack_require__ (/home/shailesh96/Denkali/denkali-website/server.js:20:30)
at Object../app.js (/home/shailesh96/Denkali/denkali-website/server.js:110:37)
at __webpack_require__ (/home/shailesh96/Denkali/denkali-website/server.js:20:30)
at Object.0 (/home/shailesh96/Denkali/denkali-website/server.js:383489:18)
at __webpack_require__ (/home/shailesh96/Denkali/denkali-website/server.js:20:30)
at ./app.js.Object.defineProperty.value (/home/shailesh96/Denkali/denkali-website/server.js:84:18)
at Object.<anonymous> (/home/shailesh96/Denkali/denkali-website/server.js:87:10)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
[nodemon] app crashed - waiting for file changes before starting...
Import lines
import '@babylonjs/core/Debug/debugLayer';
import '@babylonjs/inspector';
Commenting the above lines resolves the issue but makes me unable to use the inspector when using es6.