我正在尝试使用axios,如下所示:
import axios from 'axios';
axios.post("http://localhost:3000/test", {"prop1": "value"}, {headers: {'X-Custom-Header': 'foobar'}})
然后编译器报错:
/home/developer/Desktop/reason/interoperate/src/Ax.js:1
(function (exports, require, module, __filename, __dirname) { import axios from 'axios';
^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:74:7)
at createScript (vm.js:246:10)
at Object.runInThisContext (vm.js:298:10)
at Module._compile (internal/modules/cjs/loader.js:670:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
at startup (internal/bootstrap/node.js:238:19)
developer@monad:~/Desktop/reason/interoperate/src$ node Ax.js
/home/developer/Desktop/reason/interoperate/src/Ax.js:1
(function (exports, require, module, __filename, __dirname) { import axios from 'axios';
我导入的路径是否有误?
v10.4.0
。 使用var axios = require('axios');
是有效的。但我需要使用import
。 - softshipper