我尝试过使用babel,但我不知道什么是错的
import Product from './cart'
E:\Guc\New Folder\shopping-cart\cart.test.js:1
(function (exports, require, module, __filename, __dirname) { import Product from './cart'
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
答案 0 :(得分:0)
ES模块默认在Node.js 10 LTS中可用。从8.5.0开始,您可以使用命令行标志--experimental-modules