node.js - 升级到 Babel 7 后,无法分配给对象 ERROR 的只读属性“exports”
问题描述
在我的反应应用程序中升级到 Babel 7 后出现以下错误。如果我需要包含更多详细信息,请告诉我!
我已经尝试过替换的解决方案,module.exports
但这export default
会带来其他错误。
错误:
module.exports = {
^
TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
23 | const host = process.env.RAZZLE_HOST || `http://localhost:${port}`;
24 |
> 25 | module.exports = {
26 | port,
27 | host,
28 | isAdminSite,
config.js 上下文:
const host = process.env.RAZZLE_HOST || `http://localhost:${port}`;
module.exports = {
port,
host,
isAdminSite,
adminSiteUrl,
userSiteUrl,
导入如:
import _ from 'lodash';
import moment from 'moment-timezone';
import splitLinks from '../helpers/split-links';
import { host } from '../config';
import MatchView from './match_view';```
解决方案
基本上,您可以混合require
和export
.
export {
someObj
}
//and then import by
require('./file.js')
但你不能混用:import
用module.exports
它是行不通的。
所以,在你的情况下,module.exports
需要是export
或import
需要是require
。
推荐阅读
- java - 在 Swing 中设置关于 GridLayout 的 JPanel 的边距
- spring-boot - Java9 模块的 Spring 启动失败
- python - 使用 groupby (Pandas) 计算一列的唯一值
- vue.js - 如何从中间件或插件设置 nuxtjs 标题和元?
- tensorflow-serving - TensorFlow Serving 是否允许插件(动态链接的用户扩展)?
- junit - 如何使用 Junit LauncherDiscoveryRequest 从 Java 项目的另一个模块中的包中发现测试?
- javascript - 参考错误,但日期已定义。请指出我做错了什么
- javascript - window.location.reload 不断刷新页面
- python - 如何获取 pip 安装 `data_files` 的路径?
- java - MarkLogic Java API 中 cts:element-query 的等价物