错误:无法在模块外部使用导入?

时间:2019-10-29 23:05:57

标签: javascript node.js npm module

我从没在例如 create-react-app angular-cli 创建的样板之外使用模块,现在我试图不使用它们来模仿模块化,我得到一个error: cannot use import outside a module

这是我的package.json文件:

  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel": "^6.23.0",
    "babel-core": "^6.26.3",
    "babel-preset-env": "^1.7.0"
  }
}

我正在使用实时服务器为我的项目创建服务器,但我没有这样做:

App.js

const x = 10;
export default x;

index.js

import x from './App' // can not use import outside a module

问题是我在这里缺少什么,创建模块真正需要什么?

0 个答案:

没有答案
相关问题