aurelia / webpack-plugin

A plugin for webpack that enables bundling Aurelia applications.
MIT License
90 stars 36 forks source link

webpack 5 plugin resolves wrong modules #174

Closed MaximBalaganskiy closed 3 years ago

MaximBalaganskiy commented 3 years ago

I'm submitting a bug report

Current behavior: Importing and using @microsoft/applicationinsights-web causes a webpack error

Module not found: Error: Can't resolve 'util' in 'C:\Dev\au\webpack-plugin\tests\app-simple\node_modules\Base'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "util": require.resolve("util/") }'
        - install 'util'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "util": false }
 @ ./node_modules/@microsoft/applicationinsights-common/dist-esm/Interfaces/Contracts/Generated/Data.js 9:0-30 19:2-6
 @ ./node_modules/@microsoft/applicationinsights-common/dist-esm/applicationinsights-common.js 11:0-71 11:0-71
 @ ./node_modules/@microsoft/applicationinsights-web/dist-esm/applicationinsights-web.js 9:0-187 9:0-187 9:0-187 9:0-187 9:0-187 9:0-187 9:0-187 9:0-187 9:0-187 9:0-187 9:0-187
 @ ./src/main.ts 2:0-73 7:19-38
 @ ../../runtime/empty-entry.js

Looks like the plugin resolves node_modules/base instead of local @microsoft/applicationinsights-web/Interfaces/Contracts/Generated/Base

Expected/desired behavior:

bigopon commented 3 years ago

Can you help with a repro? My main entry looks like this

import { Aurelia, PLATFORM } from 'aurelia-framework';
import { ApplicationInsights } from '@microsoft/applicationinsights-web';

const appInsights = new ApplicationInsights({ config: {
  instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE'
  /* ...Other Configuration Options... */
} });
appInsights.loadAppInsights();
appInsights.trackPageView(); // Manually call trackPageView to establish the current user/session/pageview

export async function configure(aurelia: Aurelia) {
  aurelia.use
    .basicConfiguration();

  await aurelia.start();
  await aurelia.setRoot(PLATFORM.moduleName('app'));
}

and webpack builds just fine.

MaximBalaganskiy commented 3 years ago

The issue manifests when webpack serve

elitastic commented 3 years ago

I had to explicitly set webpack target to 'web'.

webpack.config.js

module.exports = {
    ....
    target: 'web',
    ....
}
MaximBalaganskiy commented 3 years ago

This does not help. The issue is with certain packages only and in a dev server

On Mon, 14 Jun 2021 at 7:31 pm, elitastic @.***> wrote:

I had to explicitly set webpack target to 'web'.

webpack.config.js

module.exports = { .... target: 'web', .... }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/aurelia/webpack-plugin/issues/174#issuecomment-860542288, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4KNPHYXFK6QNFFLVYY6PTTSXEAZANCNFSM46NV7N5A .