Monday, 6 December 2021

Resolving module not found with Webpack (Module not found: Error: Can't resolve 'axios' in )

I have a package A which has dependency on say, axios. Package A builds independently and works fine. However, when i try to consume package A as a dependency in package B and try to compile, I am facing issue as below:

ERROR in ./node_modules/A/dist/impl/lifecycle-associate-tool-client-impl.js Module not found: Error: Can't resolve 'axios' in '/workplace/LifeCycle/src/B/node_modules/A/dist/impl' @ ./node_modules/A/dist/impl/lifecycle-associate-tool-client-impl.js 17:32-48 @ ./node_modules/A/dist/lifecycle-client-factory.js @ ./node_modules/A/dist/index.js @ ./src/api-clients/lifecycles/lifecycles.module.ts @ ./src/application.ts

In node_modules folder at the src level of package B, i have package A and inside of package A's node_modules, i have axios.

What i am aware of is that NPM resolves dependencies by looking at node_modules directory and then looking at parent if not found. But how to resolve this inward dependency situation?

Could webpack help to resolve the axios dependency by providing path in the resolve module to look axios in the node_modules, like below?

resolve: {
    alias: {
      src: path.resolve(__dirname, "..", "src"),
    },
    modules: [path.resolve(__dirname, "..", 'src'), 'node_modules'],
    extensions: [".js", ".jsx", ".ts", ".tsx", ".json"],
  }

I dont want to specify axios as dependency in package.json of package B.

Any pointers are appreciated!



from Resolving module not found with Webpack (Module not found: Error: Can't resolve 'axios' in )

No comments:

Post a Comment