Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am implementing an application using Ionic with Webpack and Typescript. I install 'ngstorage' via npm and try to import in the entry ts file, but Webpack shows an error - 'Cannot resolve module 'angular''.

I have searched about this error and realized that I need to include the angular in the package.json file and node_modules. However, ionic-sdk module already includes angular. So it instead shows an unacceptable error in the browser that I am trying to load angular more than once.

Does Webpack have ways to skip the module resolver or point to path of angular module to ionic-sdk module instead ? or are there any other suggested ways to import ?

Thank you.

share|improve this question

I'm not familiar with ionic at all but I hope i can help you. First of all in files you use angular. on the top of file you need to import angular:

import angular from 'angular';

Then I got two suggestions that might help you:

  1. Add angular as external library

If you are certain that angular is being loaded before the bundle you create with webpack you can add angular as an external library in your webpack config:

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

Thanks to resolve.alias you can override default imports in webpack. So in your config file you can do something like:

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

As I said I'm not familiar with ionic, so I'm sorry if that's not what you were looking for :).

share|improve this answer

Using KisaneNeko's answer I was able to do the following without adding angular. This fixed the webpack issue but still gave me other issues, but maybe it'll work for you though.

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

Here is webpack's documentation for alias if you need it: https://webpack.github.io/docs/configuration.html#resolve-alias

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.