Open orsifrancesco opened 3 years ago
it is not possible to include the package https://www.npmjs.com/package/forge-dataviz-iot-react-components inside a react project made with npx create-react-app (hoping Autodesk is going to fix this problem soon).
You need to edit /node_modules/react-scripts/config/webpack.config.js
in 2 parts:
one line about PIXI
...
alias: {
'PIXI': "pixi.js/",
// Support React Native Web
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
'react-native': 'react-native-web',
// Allows for better profiling with ReactDevTools
...(isEnvProductionProfile && {
'react-dom$': 'react-dom/profiling',
'scheduler/tracing': 'scheduler/tracing-profiling',
}),
...(modules.webpackAliases || {}),
},
...
and another part about /forge-dataviz-iot-react-component
...
module: {
strictExportPresence: true,
rules: [
// Disable require.ensure as it's not a standard language feature.
{ parser: { requireEnsure: false } },
{
// "oneOf" will traverse all following loaders until one will
// match the requirements. When no loader matches it will fall
// back to the "file" loader at the end of the loader list.
oneOf: [
{
test: /forge-dataviz-iot-react-component.*.jsx?$/,
use: [
{
loader: require.resolve('babel-loader'),
options: {
presets: ["@babel/react", ["@babel/env", { "targets": "defaults" }]],
plugins: ["@babel/plugin-transform-spread"]
}
},
],
exclude: path.resolve(__dirname, "node_modules", "forge-dataviz-iot-react-components", "node_modules"),
},
// TODO: Merge this config once `image/avif` is in the mime-db
// https://github.com/jshttp/mime-db
{
test: [/\.avif$/],
loader: require.resolve('url-loader'),
options: {
limit: imageInlineSizeLimit,
mimetype: 'image/avif',
name: 'static/media/[name].[hash:8].[ext]',
},
},
...
after that on /node_modules/forge-dataviz-iot-react-components/client/components/Viewer.jsx
you will get errors about undefined Autodesk variable easily fixable changing Autodesk
with window.Autodesk
.
Although you will not see any other errors, the package will not work.
please don't leave the issue as it is
I actually don't think this is an issue with either create react app or webpack. The main
property in the package.json has been set as "./client/app.js" meaning when this package is imported, it is attempting to use the unbundled, raw JSX instead of the webpack output.
After making the following changes to the package.json, I was able to fix this issue locally.
{
"main": "./dist/bundle.js",
"files": [
"dist"
],
}
The addition of the files property is not essential but does prevent cluttering up the published package contents with resources which are not required.
As a workaround, change the import of any of the package components to target the bundle in dist. For example:
import { Viewer } from "forge-dataviz-iot-react-components/dist/bundle"; // To import component "X"
I did also experience another error at first and had to downgrade to react v16.14.0
simply including
import { Viewer } from "forge-dataviz-iot-react-components";
in a empty new react project (npx create-react-app) I get this:Any idea how to fix according with the suggestion on https://webpack.js.org/concepts#loaders ?