Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using axios error #128

Closed
aindong opened this issue Jan 20, 2016 · 10 comments
Closed

Using axios error #128

aindong opened this issue Jan 20, 2016 · 10 comments

Comments

@aindong
Copy link

aindong commented Jan 20, 2016

Hi I have a rest api and I want to use a library called Axios to do ajax requests on my api but when I tried adding the package npm install axios --save and import it into one of my component import axios from 'axios' it gives me this error

ERROR in ./~/axios/package.json
Module parse failed: /Users/alleoindong/Public/projects/restoko/restoko-desktop-app/node_modules/axios/package.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
|   "_args": [
|     [
|       "axios@^0.8.1",
 @ ./~/axios/lib/adapters/http.js 11:10-41

any work around or hints of the problem? Thank you so much for helping!

@aindong
Copy link
Author

aindong commented Jan 20, 2016

right now what I did is I added it into the externals to make the webpack build successful

@jhen0409
Copy link
Member

The axios module load .json file, so you should add json-loader to webpack config. :)

@aindong
Copy link
Author

aindong commented Jan 20, 2016

after adding json-loader I got this

ERROR in ./app/index.js
Module build failed: SyntaxError: Unexpected token i
    at Object.parse (native)
    at Object.module.exports (/Users/alleoindong/Public/projects/restoko/restoko-desktop-app/node_modules/json-loader/index.js:7:48)
 @ multi main

putting it into the externals is working.

@chentsulin
Copy link
Member

axios package has http(for node) and xhr(for browser) adapters, and electron renderer can run both or two. Notice that, http adapter can't be packed by webpack.

You can list axios in externals as a quick work around. Or try to replace "./lib/adapters/http.js" to "./lib/adapters/xhr.js" via webpack, see also https://github.com/mzabriskie/axios/blob/master/package.json#L61

@calderaro
Copy link

i have exactly the same problem.
| { | "_args": [ | [ | "axios@^0.9.1", @ ./~/axios/lib/adapters/http.js 10:10-41
and when i try with externals.
ReferenceError: axios is not defined

replace "./lib/adapters/http.js" to "./lib/adapters/xhr.js" seems to work.

@harrisrobin
Copy link

None of the solutions mentioned above solved it for me. Could someone guide me to an example of this boilerplate using axios or any other HTTP library? Would be much appreciated! Thanks

@jhen0409
Copy link
Member

The axios module load .json file, so you should add json-loader to webpack config. :)

This is real... see this branch, it work.

@chentsulin is right, but it just problem of json file.

@harrisrobin
Copy link

@jhen0409 thank you for this.

One mistake I was also making is saving json-loader to devDependencies. After looking at @jhen0409 's example, when saving json-loader to dependencies it worked.

@chentsulin
Copy link
Member

@jhen0409 Should we support json-loader as default loaders?

@jhen0409
Copy link
Member

Should we support json-loader as default loaders?

I think yes, because node require json file is natural, but it was broken by webpack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants