我发现此修复程序解决了我试图在我正在开发的包中使用钩子并尝试使用多个 React 实例时出错的问题。这对我有用,但我想知道当我准备好从 NPM 测试我的包时如何“撤消”所有这些。当我只是使用'npm link'时,我会做'npm unlink'。我将如何在这里应用它并使我的应用程序恢复到原始状态,尤其是在应用程序内的第一部分,使用 pushd 和 popd。
I was using npm link between an app and a module I was actively working on,
and I had to fix it by linking the app's react and react-dom to the module,
then linking the module to the app:
in app:
pushd node_modules/react && npm link; popd
pushd node_modules/react-dom && npm link; popd
in module:
npm link # this creates a global link for module.
npm link react && npm link react-dom # link app's react and react-dom, so they're in sync.
in app:
npm link [module-name] # this replace the module lib in node_modules with a link to the module's local copy.