Cannot resolve 'angular' module when importing ngstorage using Ionic and Webpack

I am using the Ionic app with Webpack and Typescript. I install "ngstorage" via npm and try to import entries into the ts file, but Webpack shows an error - "Cannot resolve the module" angular ".

I was looking for this error and realized that I need to include angular in the package.json and node_modules file. However, the ionic-sdk module already includes angular. So instead, an invalid browser error is displayed, which I try to download angular more than once.

Does Webpack have any way to skip the module recognizer or provide the angular module path for the ionic-sdk module? or are there any other suggested import methods?

Thank.

+4
source share
2 answers

I am not familiar with ionic, but I hope that I can help you. First of all, in files you use angular. at the top of the file you need to import angular:

import angular from 'angular';

Then I got two suggestions that might help you:

  • Add angular as an external library

If you are sure that angular loads before creating the package using webpack, you can add angular as an external library to your web package configuration:

externals: [
  'angular'
]
  1. "Teach" webpack where to look for angular

Thanks to the .alias solution, you can override the default import in webpack. Therefore, in your configuration file, you can do something like:

resolve: {
  alias: {
    angular: 'path/to/sdk/angular'
  }
}

, , , , :).

+5

KisaneNeko, angular. -, , , , .

  resolve: {
      alias: {
          'angular': '../../node_modules/ionic-sdk/release/js/ionic.bundle.js',
      }
  }

webpack , : https://webpack.imtqy.com/docs/configuration.html#resolve-alias

+1

All Articles