问题描述
我在尝试将我的应用程序部署到 Heroku 时陷入了一个循环.由于无法在 Common JS 中加载 ES6 模块",我的导入语句(例如 import cors from 'cors'
)似乎阻止了应用程序在生产中启动.错误.在本地它运行得很好.
I'm caught in a bit of a loop trying to deploy my app to Heroku. My import statements (e.g. import cors from 'cors'
) seem to prevent the app from launching in production, due to the "Cannot Load ES6 Modules in Common JS" error. Locally it runs just fine.
但是,当我尝试通过将 "type": "module"
添加到我的 package.json
来解决上述错误时,我得到了一组全新的错误,应用程序将不再在本地运行.我相信这个错误是由于我初始化 sequelize 和关联模型的方式造成的,但我不确定.我想解决这个错误,但需要帮助导入新的语法......我想.
However, when I attempt to resolve the above error by adding "type": "module"
to my package.json
I get a whole new set of errors and the app will no longer run locally. I believe this error is due to the way I'm initializing sequelize and associated models but I am unsure. I'd like to resolve this error but need a hand with new syntax for the imports... I think.
错误,package.json
和 index.js
包括在下面.
Error, package.json
and index.js
include below.
错误文字
Package.JSON
Index.js
想法或指示?谢谢!
推荐答案
在 Node.js 中,import 语句只允许在 ES 模块中使用.因此,目录导入在 Node.js 中不起作用.阅读 Node.js 文档.
In Node.js, import statements are permitted only in ES modules. so, directory imports do not work in Node.js. Read Node.js Documentation.
这篇关于错误 [ERR_UNSUPPORTED_DIR_IMPORT]:尝试在本地启动 Nodejs 应用程序时导入目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!