How to make a linked component peerDepdencies use the equivalent node_modules of the script being linked to?

前端 未结 1 1205
Happy的楠姐
Happy的楠姐 2021-01-23 17:17
  • I am using npm version 3 (version relevant because of the new way peerDependencies behave in version 3).
  • I have a reactjs app called \"game\" and a reactjs compon
1条回答
  •  说谎
    说谎 (楼主)
    2021-01-23 17:44

    After a bit of digging, I have found a solution in the webpack documentation: npm linked modules doesn’t find their dependencies.

    Simply add resolve.fallback (and resolveLoader.fallback if your dependencies have loader specific logic, such as using CSS Modules) to your webpack config:

    resolve: {
        fallback: path.resolve(__dirname, './node_modules')
    },
    resolveLoader: {
        fallback: path.resolve(__dirname, './node_modules')
    }
    

    The fallback setting will make webpack loader look into the local ./node_modules path for any dependencies that cannot be resolved, including the dependencies of the dependencies of the main app itself. As a result, all peerDependencies of the main app dependencies will be resolved against the main app ./node_modules.

    0 讨论(0)
提交回复
热议问题