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.

Webpack build failing with "Cannot read property 'bindings' of null"

See original GitHub issue

I’m seeing some unusual behavior when add the design-system-react to my build. When it is not present, this builds successfully as expected:

src/index.js

import React from 'react';
import ReactDOM from 'react-dom';
import Test from './Test';

ReactDOM.render(<Test/>, document.getElementById('app'));

When I add path.join(__dirname, 'node_modules/@salesforce/design-system-react') to my webpack config and "@salesforce/babel-preset-design-system-react" to my babelrc file, the build fails with the error in the subject.

Oddly, if I remove the import of the Test component and use

ReactDOM.render(<p>Hi from index</p>, document.getElementById('app')); in my index file, the compile is successful.

Here are the relevant files:

webpack.config.js

const path = require('path');
const webpack = require('webpack'); // doesn't seem to be used
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
    entry: './src/index.js',
    output: {
        path: path.join(__dirname, '/dist'),
        filename: 'bundle.js',
        publicPath: '/'
    },
    resolve: {
        extensions: [
            '.js',
            '.jsx'
        ]
    },
    module: {
        rules: [
            {
                test:/\.(jsx?)$/,
                exclude: /node_modules/,
                include: [
                    path.join(__dirname, 'src'),
                    path.join(__dirname, 'node_modules/@salesforce/design-system-react')
                ],
                use: {
                    loader: 'babel-loader'
                }
            },
            {
                test: /\.css$/,
                loader: ExtractTextPlugin.extract(
                    'style-loader',
                    'css-loader?url=false&outputStyle=expanded&sourceMap=true&sourceMapContents=true'
                )
            },
            {
                test: /\.(svg|gif|jpe?g|png)$/,
                loader: 'url-loader?limit=10000'
            },
            {
                test: /\.(eot|woff|woff2|ttf)$/,
                loader: 'url-loader?limit=30&name=assets/fonts/webfonts/[name].[ext]'
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './src/index.html'
        }),
        new ExtractTextPlugin('[name].css')
    ]
}

.babelrc

{
    "presets": ["@babel/preset-env", "@babel/preset-react", "@salesforce/babel-preset-design-system-react"]
}

src/Test.js

import React from 'react';

class Test extends React.Component {
    render() {
        return(
            <p>Hi from test</p>
        );
    }
}

export default Test;

I’m fairly new to babel and webpack so hope it’s not something obvious I’m missing.

I’ve looked through the existing open and closed issues, but can’t find anything similar. Hoping someone can help as I’d really like to use this library with a current project.

Thanks.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cakirlarccommented, May 5, 2022

As the source code of preset at https://github.com/salesforce/design-system-react/blob/master/preset/index.js evolved

Here is an update for @CrazyByDefault 's sample solution. I hope it helps people like me diving into this library.

In your webpack config, add these rules/options for babel-loader:

        module: {
            rules: [
                {
                    test: /\.jsx?$/,
                    include: [
                        'node_modules/@salesforce/design-system-react',
                    ].map(
                        someDir => path.resolve(
                            process.cwd(),
                            someDir
                        )
                    ),
                    loader: require.resolve('babel-loader'),
                    options: {
                        presets: [
                            "@babel/preset-env",
                            "@babel/preset-react",
                        ]
                    }
                },
            ]
        }

1reaction
CrazyByDefaultcommented, Jul 21, 2019

Hi, an update for those looking to build them in webpack and not use named imports

We were able to build using these presets, which are simply the updated babel7+ valid versions of the packages that the salesforce wrapper tries to import here https://github.com/salesforce/design-system-react/blob/master/preset/index.js

In your webpack config, add these options for babel-loader:

loader: 'babel-loader',
options: {
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react",
    {
        "plugins": [
          "@babel/plugin-proposal-object-rest-spread",
          "@babel/plugin-proposal-export-default-from",
          "@babel/plugin-proposal-export-namespace-from",
          [
              "@babel/plugin-proposal-class-properties",
              {
                  "loose": true
              }
          ]
        ]
    }
  ]
}

and you should be good!

@interactivellama maybe this should be added to the main README instead of importing the now outdated preset?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrade to Babel 7: Cannot read property 'bindings' of null
Here is the sample webpack config section where you should change the preset: use: { loader: 'babel-loader', options: { // Here you should ......
Read more >
Cannot read property 'bindings' of null · Issue #8908 - GitHub
I've set the babel core and preset-env to be the exact same version. How do i fix this issue? webpack.config.js. const path =...
Read more >
Babel v7 error: "Cannot read property 'bindings' of null"
A solution. And install @babel/preset-env as devDependencies. All set. Hope this blog post was something you were looking for!
Read more >
TypeError: Cannot read property 'bindings' of nul-babel.js
Coding example for the question Webpack Babel - Module build failed: TypeError: Cannot read property 'bindings' of nul-babel.js.
Read more >
如何解决Cannot read property 'bindings' of null_朱知知的博客
Cannot read property 'xxxxxx' of null 问题原因: 前面有一个空的id,我在后面给他加了id,导致无法读取属性。去掉前面空id就好了。另外又博主也发生 ...
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