-
Notifications
You must be signed in to change notification settings - Fork 434
Description
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.
Activity
welcome commentedon Oct 25, 2018
Thanks for opening your first issue! 👋
If you have found this library helpful, please star it. A maintainer will try to respond within 7 days. If you haven’t heard anything by then, please bump this thread.
interactivellama commentedon Nov 1, 2018
Since you are new, I will ask, did you
npm install @salesforce/babel-preset-design-system-react
?If that doesn't work, I do know plenty of folks that do use the named import version without issue. The primary reason that I recommend the source code version is that there are so many different ways to build things, and so many engineers that want to micro-optimize things their own way, and I don't want to debug folks webpack configs. 😉 I can just say, uh here's the source, go to town with your own build.
interactivellama commentedon Nov 1, 2018
The repo itself is using the babel plugin for storybook, so you might look there. I'm going to close this issue, since the named import version shouldn't require babel presets. Feel free to re-open with new information and to hopefully post what the issue was so other can learn. 🎉
evanmcd commentedon Nov 5, 2018
Hey @interactivellama thanks for the response. I've ended up just importing the main SLDS CSS and a static resource, rather than getting it into webpack, and am now using the named import version instead of the source code.
It's working, so... I'm good with it.
Thanks.
davidakerr commentedon Jun 3, 2019
Adding the babel preset to a fresh create react app breaks serviceWorker.js
TypeError: Cannot read property 'bindings' of null
interactivellama commentedon Jun 3, 2019
I guessing we have old Babel presets.
The preset config is located at
https://github.com/salesforce/design-system-react/tree/master/preset
But eventually will be moved to https://github.com/salesforce/babel-preset-design-system-react
davidakerr commentedon Jun 4, 2019
@interactivellama I'm trying to use the master branch in my project in order to add some features to the input elements (I find the way the components are written to be easier to work with). I get the error:
Do I have any hope of using the master branch ?
interactivellama commentedon Jun 20, 2019
That's the first line that has a default export in the library, which means https://babeljs.io/docs/en/babel-plugin-proposal-export-default-from is probably not working.
There are three versions of the preset. You might try 3.0. Currently this library is installing 1.0
"@salesforce/babel-preset-design-system-react": "^1.0.0",
CrazyByDefault commentedon Jul 21, 2019
Hi,
We've been running into the same issues as above while trying to use the preset:
Like you mentioned @interactivellama, the preset seems to be a wrapper for outdated Babel presets. Why not simply ask users to use the presets in their own
.babelrc
and not serve this package? As such I don't see the use of it, except requiring additional maintenance.CrazyByDefault commentedon 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:
and you should be good!
@interactivellama maybe this should be added to the main README instead of importing the now outdated preset?
interactivellama commentedon Jul 22, 2019
@CrazyByDefault Link to your issue comment added in readme. Thank you! https://github.com/salesforce/design-system-react/blob/master/README.md#transpile-with-babelrc-settings
cemcakirlar commentedon 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:
shannonio commentedon Jun 22, 2022
Does anyone know the equivalent changes that might need to be made to get this to work with Parcel instead of webpack?
I am experiencing these same issues and have tried updating my babelrc to no avail and still getting this error on every compile:
0xW1sKy commentedon Nov 29, 2022
for anyone else struggling this even after reading the full series of comments above, here is my working config
Note: i'm not using any
.babelrc
files.<APP_ROOT>/webpack.config.js
<APP_ROOT>/packages.json