Closed agarwalishan closed 3 years ago
Please can you rather give us a reproducible project that can be cloned instead of pasting code here which is not escaped and/or quoted correctly since we then have to try and piece together bits and pieces of an incomplete integration.
Hey I have made a react component in which I am using projectstorm. I made npm package for this component so that I can re-use it in different react web-apps according to my requirement. When I import this npm package in a React app and run it, everything works fine but when I build it i.e. (react-scripts build) and then verify it by running server in build folder I got this error.
When I look into index.js:118 I found that problem is in following line
const engine = createEngine();
So I believe there is some bug in projectstorm library or I have not bundled the component correctly using webpack to make npm package. Here is code for the component in which I am using this library. Also I have added codes for other related files to bundle it as npm package.
DemoReactComponent.js
`import React from 'react'; import createEngine, { DefaultLinkModel, DefaultNodeModel, DiagramModel } from '@projectstorm/react-diagrams';
import { CanvasWidget } from '@projectstorm/react-canvas-core';
class StormDiagrams extends React.Component {
}
export default StormDiagrams;`
index.js
import Demo from './Demo/Demo.js'; export default Demo;
webpack.config.js
`const path = require("path"); const autoprefixer = require('autoprefixer');
module.exports = { mode: "production", entry: "./src/index.js", output: { path: path.resolve("build"), filename: "index.js", libraryTarget: "umd", library: "plowchart" }, module: { rules: [ { test: /.(ts|tsx)$/, include: [/\/node_modules\/@projectstorm/], loader: 'ts-loader', //exclude: /node_modules/ }, { test: /.(js|ts|tsx)$/, include: [path.join(__dirname, 'src'), /\/node_modules\/@projectstorm/], loader: 'babel-loader', //exclude: /node_modules/ }, { test: /.css$/, exclude: /node_modules/, use: [ { loader: 'style-loader' }, { loader: 'css-loader', options: { importLoaders: 1, modules: true, localIdentName: '[name][local][hash:base64:5]' } }, { loader: 'postcss-loader', options: { ident: 'postcss', plugins: () => [ autoprefixer({ browsers: [ "> 1%", "last 2 versions" ] }) ] } } ] }, { test: /.(png|jpe?g|gif)$/, loader: 'url-loader?limit=8000&name=images/[name].[ext]' } ] }, externals: { react: {
commonjs: "react",
commonjs2: "react",
amd: "React",
root: "React"
},
"react-dom": {
commonjs: "react-dom",
commonjs2: "react-dom",
amd: "ReactDOM",
root: "ReactDOM"
} } };`
I think there is no need of ts-loader and also packaging 'node_modules/projectstorm' but I have added this after going through issue #514, #440, #521.
.babelrc
{ "presets": ["@babel/preset-react", "@babel/preset-env"], "plugins": [ "@babel/plugin-proposal-class-properties", "@babel/plugin-proposal-export-default-from" ] }
package.json
{ "name": "plowchart", "version": "1.0.7", "description": "reusable component", "main": "build/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "webpack" }, "author": "ishan", "license": "", "devDependencies": { "@babel/core": "^7.7.5", "@babel/plugin-proposal-export-default-from": "^7.10.4", "@babel/preset-env": "^7.7.6", "@babel/preset-react": "^7.7.4", "babel-preset-stage-2": "^6.24.1", "babel-loader": "^8.0.6", "css-loader": "^0.28.7", "style-loader": "^0.19.0", "file-loader": "^1.1.5", "postcss-loader": "^2.0.7", "url-loader": "^0.6.2", "webpack": "^4.41.2", "webpack-cli": "^3.3.10", "webpack-dev-server": "^2.9.1", "autoprefixer": "^7.1.5", "react": "^16.13.1", "react-dom": "^16.13.1", "antd": "^4.6.2", "@emotion/core": "^10.", "@emotion/styled": "^10.", "@projectstorm/react-diagrams": "^6.2.0", "closest": "^0.0.1", "lodash": "4.", "resize-observer-polyfill": "^1.5.1", "dagre": "^0.8.4", "pathfinding": "^0.4.18", "paths-js": "^0.4.9", "ml-matrix": "^6.5.0", "ts-loader": "^7.0.5", "typescript": "^3.9.3", "source-map-loader": "^1.0.0" }, "dependencies": { "@projectstorm/react-diagrams": "^6.2.0", "antd": "^4.6.2", "closest": "^0.0.1", "lodash": "4.", "resize-observer-polyfill": "^1.5.1", "@emotion/styled": "^10.", "@emotion/core": "^10.", "dagre": "^0.8.4", "pathfinding": "^0.4.18", "paths-js": "^0.4.9", "ml-matrix": "^6.5.0" } }