Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

./node_modules/forge-dataviz-iot-react-components/client/components/BasicTree.jsx 107:16 loaders error? #4

Open
orsifrancesco opened this issue Sep 2, 2021 · 3 comments

Comments

@orsifrancesco
Copy link

simply including import { Viewer } from "forge-dataviz-iot-react-components"; in a empty new react project (npx create-react-app) I get this:

./node_modules/forge-dataviz-iot-react-components/client/components/BasicTree.jsx 107:16
Module parse failed: Unexpected token (107:16)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|         if (node.children.length > 0) {
|             return (
>                 <TreeItem
|                     id={`tree-node-${node.id}`}
|                     key={node.id}

Any idea how to fix according with the suggestion on https://webpack.js.org/concepts#loaders ?

@orsifrancesco
Copy link
Author

orsifrancesco commented Sep 4, 2021

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.

@aliakseivedae
Copy link

please don't leave the issue as it is

@cturner8
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants