reactjs - ES6 import not working correctly in next.js application
问题描述
I'm working on a tiny next.js
project, but the issue that i'm facing is that ES6 module import
only works in React components
.The 2 following code are some Database configurations that are used in routes inside API folder
.
The code below is the one that doesn't work using ES6 modules
Here is the code that works fine with common js
Also when i use the debugger, with the code using ES6 modules, i cannot capture values form imported modules and i only capture values when using common js.
I've tried to solve the problem with this github issue : Support ES module in next.config.js but id did not help. Have any idea?
解决方案
ES6 导入不起作用,因为这是服务器端渲染。
我建议你使用 requirejs。
但是如果你想在 NodeJS 中使用 ES6 导入,它可以在新版本中使用,现在它是一个实验性功能(你可以在这里阅读更多)
尝试解决方案:在 NodeJS 上更新到最新版本
推荐阅读
- linux - 在 bash 中解析标准输出
- c - 使用 fwrite 存储在文本文件中的数据在 C 中是不可读的
- mongodb - 在 Spring Data 中查询投影内的数组
- java - 如何解决:E/Volley:[230] BasicNetwork.performRequest:http://192.168.43.83/test.php 的意外响应代码 403
- powershell - 用于为 Azure 数据工厂构建 CI/CD 的 Powershell 脚本
- reactjs - 从 API 中提取数据到 react-bootstrap-table-2
- carrot2 - 当我创建一个本地 xml 文件时,导入 carrot2 时出错
- swift - 二元运算符“===”不能应用于“Self.Element”和“AnyObject”类型的操作数
- sql - db2 将 double 转换为 varchar 而不会丢失零
- php - Laravel 模型转换无法正常工作