Reputation: 731
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
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
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