-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React-leaflet: nullish coalescing operator error #58
Comments
Hello, |
No. It doesn't work. |
fast-serve is just an "extension" on top of the SPFx, it means that you should make the SPFx build work first. You cannot package your solution for production with fast-serve only, thus you have to set up OOB build anyway. I took a look at the library you mentioned and tried to implement the suggested workaround on top of the SPFx. I haven't found any other way except adding babel to SPFx to transpile the leaflet sources (like in the linked issue). So the process of "enabling" leaflet with SPFx and fast-serve is:
build.configureWebpack.mergeConfig({
additionalConfiguration: (generatedConfiguration) => {
generatedConfiguration.module.rules.push(
{
test: /node_modules[\/\\]@?react-leaflet[\/\\].*.js$/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', { targets: "defaults" }]
],
plugins: ['@babel/plugin-proposal-nullish-coalescing-operator']
}
}
}
);
return generatedConfiguration;
}
}); The above config adds babel-loader for all <MapContainer center={[51.505, -0.09]} zoom={13} scrollWheelZoom={false} style={{
height: "400px"
}}>
<TileLayer
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
</MapContainer>
const transformConfig = function (initialWebpackConfig) {
// transform the initial webpack config here, i.e.
// initialWebpackConfig.plugins.push(new webpack.Plugin()); etc.
initialWebpackConfig.module.rules.push(
{
test: /node_modules[\/\\]@?react-leaflet[\/\\].*.js$/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', { targets: "defaults" }]
],
plugins: ['@babel/plugin-proposal-nullish-coalescing-operator']
}
}
}
);
return initialWebpackConfig;
} With this setup, it works with gulp serve and fast-serve as well. For simplicity, I pushed a configured solution here. |
It works!👍 |
The dist code should be |
Hi,
I have a question about a webpack config. I would be grateful if you could help me)
I've installed
![image](https://user-images.githubusercontent.com/28485877/149673860-4bcf176c-1d37-4f41-b0d7-669a36548ed0.png)
react-leaflet
in my project and got this error.I found a solution.
PaulLeCam/react-leaflet#883
But don't know how to add the babel plugin to the webpack config.
https://babeljs.io/docs/en/babel-plugin-proposal-nullish-coalescing-operator
Thanks)
Config
The text was updated successfully, but these errors were encountered: