score:2
With Webpack you can use resolve.alias
a long with npm/yarn link in order to have all dependencies use a single instance of React from your host app.
In your development Webpack config add the following:
resolve: {
alias: {
react: path.resolve('./node_modules/react'),
},
},
score:0
The externals in webpack config will be useful.
// webpack.config.js
module.exports = {
//...
externals: ['react', 'react-dom'],
}
Normally the react component library does not need to be installed react.
score:1
The option I'm currently using on my projects consist of skipping npm
/yarn
linking at all, and add a NPM script to symlink any local package into node_modules
folder like:
- create an empty
node_modules
folder - run local dependencies linking script
- install NPM dependencies from root project
If module and the hosting project declares compatible React
dependencies you should end up with your local module symlinked and just one React
instance installed.
You might also want to automate local dependencies linking with tools like this.
Source: stackoverflow.com
Related Query
- Need a "yarn/npm link" workflow for dev and publishing for "multiple copies of react" module
- Use multiple web.config files for qa, dev and prod in a REACTJs project
- Why do you need to import React multiple times in parent and child components?
- No need for state in React components if using Redux and React-Redux?
- Symlinking react modules with npm link for local development gives error
- Duplicate ReactJS import issue when using npm link to test component before publishing as npm package
- How to link schema in "GraphQL for .NET" and "Relay"?
- What's the difference between npm run dev and npm run start in Next.js?
- Publishing mocks for an npm package to be used by jest's module mocking system
- Yarn workspaces and yarn link
- Why does chrome dev tools console show a link for Post 500 error in one website but not another?
- How to create multiple entries and output for create-react-app and keep them separated?
- Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings
- How to properly use peerDependencies when publishing an NPM module (React component) with webpack? And use with npm link?
- Video.js - Why need both npm module and <script> tag?
- Does it need to rebuild everytime for new posts? Using gatsby and WordPress
- Best workflow for developing npm packages that depend on each other
- How to manage multiple versions of npm modules in a project for different packages internally dependent on specific versions?
- Why is requestAnimation frame called multiple times for some frames, and not at all for others?
- NavLink active on same link for multiple URLs in React Router DOM
- Multiple event handlers for the same event and element with Reactjs
- Minified React error #310; use the non-minified dev environment for full errors and additional helpful warnings using Chrome through Selenium in React
- How to bundle module without dependencies for publishing npm package
- Some issue has been occurring for 2 days and I am unable to solve it in npm start
- NPM and Yarn Registry issues while creating react app
- Correct way to use ref with Next.js for a Link and an <a>?
- How to move react event handlers to separate file ,export and then import for reuse in multiple different functional components?
- basic explain for what does npm start do with my reactjs code and how to run it from browser
- ReferenceError: window is not defined in getServerSideProps for Next.js App And I Need to Store A Variable Persistantly in The getServerSideProps Func
- npm uninstall -g create-react-app and yarn global remove create-react-app not working
More Query from same tag
- Open menu on mouseover and Close menu on mouseleave in react
- how to remove whitespace from password validation in react
- Type a prop to accept either one interface or another interface
- getting errors in retrieving information through inputs
- axios.post request gets 404
- How to send formData that includes image
- Pure ReactJS Components
- React ES6 component modal API
- this.props.dispatch is not a function
- Handling state and arrays of objects in React
- Layout mismatch between development & build in Gatsby
- Toggle switch in reactjs
- Redirect with state values in react
- Background image with gradient overlay React
- I need to have some fields in ui-schema which do not exist in schema section
- How to use button id dynamic in post request in reactjs
- react-tsparticles is hiding my other components when i just want it to be a backgroud
- React event target value from jsx element does not get bind to state and json array (Type error cannot read the properties of undefined )
- ReactJs hook reducer filtering through array based off user string input
- How can I return a React Component from a function and render it onClick?
- Embed <script> tag into React Gatsby Component
- React portal popup window variable
- set multiple states, and push to state of array in one onClick function
- Counter to redirect on three failed login attempts does nothing
- How to proper use Ajax in React
- Prevent rerender on function prop update
- How to put a spy on clearInterval() in sinon?
- React how to toggle onclick to false after you already clicked?
- How to make a dependent mutation in react query?
- ReactJs input first value getting empty