javascript - 错误:不能在模块外使用导入?
问题描述
我从未使用过由例如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"
}
}
我正在使用实时服务器为我的项目创建服务器,但我没有这样做:
应用程序.js:
const x = 10;
export default x;
index.js:
import x from './App' // can not use import outside a module
问题是我在这里缺少什么,创建模块我真正需要什么?
解决方案
推荐阅读
- time-series - 测量精度错误打印不适用
- php - 在 Laravel Blade 模板中的 AJAX 响应中出现错误
- keycloak - 如何通过keycloak中的自定义属性获取用户?
- javascript - 如何使用 mongodb native、express 和 body-parser 来发布请求和保存数据?
- android - 将 android studio 从 3.2 更新到 3.3 后出现错误
- python - 无法安装python模块
- javascript - 当输入提供为“2018.1”时,如何获得针对季度的输出,例如“FY18 Q1”?
- python - 如何避免使用全局变量?
- .net - .Net Core 2.1 应用程序在使用 Docker 部署到 Heroku 时崩溃
- security - 如果我不存储密钥,加密我的 JWT 身份验证令牌客户端是否安全?