Webpack alliases work in browser, but not in node

Viewed 12

To start off, this is my first post on stackoverflow so I hope I'm doing it right...

So my Webpack alliases work in browser, but not in node

I have a package (let's call it Services) with a subfolder dev and another project (let's call it MobX) which uses Services. In Mobx, I have a webpack configuration which is supposed, in development mode, change the paths of Services to have access to the subfolder dev instead.

Here's a sample of the code :

const devConfig = {
  ...commonConfig,
  mode: "development",
  devtool: "cheap-module-source-map",
  entry: "./src/lib/index.ts",
  output: {
    path: outputDir,
    library: name,
    libraryTarget: "umd",
    globalObject: "this",
  },
  optimization: {
    minimize: false,
  },
  plugins: [...commonConfig.plugins, forkTsCheckerWebpackPlugin],
  resolve: {
    ...commonConfig.resolve,
    alias: {
      "@intuition/services-apis$": "@intuition/services-apis/dev",
    },
  },
};

const devConfigNode = {
  ...devConfig,
  target: ["node"],
  name: "node",
  output: {
    ...devConfig.output,
    filename: splitChunks ? "[name].[contenthash].node.js" : "index.node.js",
  },
};

const devConfigBrowser = {
  ...devConfig,
  target: ["web", "es5"],
  name: "browser",
  output: {
    ...devConfig.output,
    filename: splitChunks ? "[name].[contenthash].browser.js" : "index.browser.js",
  },
};

I don't understand why, in node, it doesn't go into @intuition/services-apis/dev. In works fine in browser but no matter what I do, in node, it doesn't work. I have been at this day for days now and I can't seem to figure it out.

If my explanation wasn't clear enough and needs more details, please do not hesitate to ask any question.

0 Answers
Related