John williams
John williams

Reputation: 731

Not letting me import modules in Ember js for some reason or an another

I have just started a small Ember project just to get my self familiar with it and it's causing me a headache at the moment because it just refuses to play ball with npm imports.

So i have a component that i am trying to import axios into and it just keeps saying Could not find module npm:axios and for the life of me i cant figure our why.

Here is my code

import Component from '@ember/component';
import axios from 'npm:axios';

import emailValidate from '../validators/email';

export default Component.extend({
  isValidEmail: false,
  actions: {
    onChange: function(value) {
      this.set('isValidEmail', emailValidate(value));

      if (emailValidate(value)) {

        axios.get('http://localhost:3000/users/').then(function (response) {
      // handle success
      console.log(response);
    })
  }
  },

 }
});

I have also tried import axios from 'axios'

Upvotes: 1

Views: 1010

Answers (2)

bartocc
bartocc

Reputation: 737

In order to import from an npm package in an ember app, The Octane Edition of Ember recommends to use ember-auto-import.

To do this, at the root of your ember app, run:

ember install ember-auto-import

Then, after adding axios to your package.json via npm install -D axios or yarn add -D axios, you will be able to import it with

import axios from 'axios';
// import axios from 'npm:axios'; this import is wrong

Upvotes: 4

prat_bhan
prat_bhan

Reputation: 139

Do you have entry of axios in package.json. you first have to install axios in your node_modules by: npm install axios --save. This will make entry into package.json Then restart your server. This should fix your issue. P.S: Not sure why you have imported like 'npm:axios' instead import axios from 'axios'; I hope that solves your problem.

Upvotes: -1

Related Questions