• <tfoot id='Vtqnf'></tfoot>
  • <legend id='Vtqnf'><style id='Vtqnf'><dir id='Vtqnf'><q id='Vtqnf'></q></dir></style></legend>
    <i id='Vtqnf'><tr id='Vtqnf'><dt id='Vtqnf'><q id='Vtqnf'><span id='Vtqnf'><b id='Vtqnf'><form id='Vtqnf'><ins id='Vtqnf'></ins><ul id='Vtqnf'></ul><sub id='Vtqnf'></sub></form><legend id='Vtqnf'></legend><bdo id='Vtqnf'><pre id='Vtqnf'><center id='Vtqnf'></center></pre></bdo></b><th id='Vtqnf'></th></span></q></dt></tr></i><div id='Vtqnf'><tfoot id='Vtqnf'></tfoot><dl id='Vtqnf'><fieldset id='Vtqnf'></fieldset></dl></div>

    1. <small id='Vtqnf'></small><noframes id='Vtqnf'>

        • <bdo id='Vtqnf'></bdo><ul id='Vtqnf'></ul>

      1. 错误 [ERR_UNSUPPORTED_DIR_IMPORT]:尝试在本地启动 Nodejs 应用程序时导入目录

        时间:2023-09-04

        • <tfoot id='YDyD3'></tfoot>
            <bdo id='YDyD3'></bdo><ul id='YDyD3'></ul>
            <legend id='YDyD3'><style id='YDyD3'><dir id='YDyD3'><q id='YDyD3'></q></dir></style></legend>

                <small id='YDyD3'></small><noframes id='YDyD3'>

              1. <i id='YDyD3'><tr id='YDyD3'><dt id='YDyD3'><q id='YDyD3'><span id='YDyD3'><b id='YDyD3'><form id='YDyD3'><ins id='YDyD3'></ins><ul id='YDyD3'></ul><sub id='YDyD3'></sub></form><legend id='YDyD3'></legend><bdo id='YDyD3'><pre id='YDyD3'><center id='YDyD3'></center></pre></bdo></b><th id='YDyD3'></th></span></q></dt></tr></i><div id='YDyD3'><tfoot id='YDyD3'></tfoot><dl id='YDyD3'><fieldset id='YDyD3'></fieldset></dl></div>
                  <tbody id='YDyD3'></tbody>
                  本文介绍了错误 [ERR_UNSUPPORTED_DIR_IMPORT]:尝试在本地启动 Nodejs 应用程序时导入目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在尝试将我的应用程序部署到 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.jsonindex.js 包括在下面.

                  Error, package.json and index.js include below.

                  错误文字

                  [nodemon] starting `babel-node src/index.js`
                  internal/process/esm_loader.js:74
                      internalBinding('errors').triggerUncaughtException(
                                                ^
                  
                  Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/Users/jeff/Clients/Bummer/Code/Server/src/models' is not supported resolving ES modules imported from /Users/jeff/Clients/Bummer/Code/Server/src/index.js
                      at finalizeResolution (internal/modules/esm/resolve.js:272:17)
                      at moduleResolve (internal/modules/esm/resolve.js:699:10)
                      at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11)
                      at Loader.resolve (internal/modules/esm/loader.js:85:40)
                      at Loader.getModuleJob (internal/modules/esm/loader.js:229:28)
                      at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:51:40)
                      at link (internal/modules/esm/module_job.js:50:36) {
                    code: 'ERR_UNSUPPORTED_DIR_IMPORT',
                    url: 'file:///Users/jeff/Clients/Bummer/Code/Server/src/models'
                  }
                  [nodemon] app crashed - waiting for file changes before starting...
                  

                  Package.JSON

                  {
                    "name": "bummer",
                    "type": "module",
                    "version": "1.0.0",
                    "description": "",
                    "main": "index.js",
                    "scripts": {
                      "start": "node src/index.js",
                      "dev": "nodemon --exec babel-node src/index.js",
                      "test": "echo "Error: no test specified" && exit 1"
                    },
                    "keywords": [],
                    "author": "",
                    "license": "ISC",
                    "devDependencies": {
                      "@babel/core": "^7.9.6",
                      "@babel/node": "^7.8.7",
                      "@babel/preset-env": "^7.9.6",
                      "nodemon": "^2.0.4",
                      "sequelize-cli": "^6.2.0"
                    },
                    "dependencies": {
                      "cookie-parser": "^1.4.5",
                      "cors": "^2.8.5",
                      "dotenv": "^8.2.0",
                      "express": "^4.17.1",
                      "pg": "^8.2.1",
                      "querystring": "^0.2.0",
                      "request": "^2.88.2",
                      "sequelize": "^6.3.5",
                      "sequelize-auto-migrations": "^1.0.3",
                      "uuid": "^8.0.0"
                    }
                  }
                  

                  Index.js

                  import cors from 'cors';
                  import express from 'express';
                  import models, { sequelize } from './models';
                  // import routes from './routes';
                  
                  //Initiaze Express
                  const app = express();
                  const routes = require('./routes');
                  
                  
                  //Helpers for Spotify oAuth
                  const cookieParser = require('cookie-parser')
                  
                  
                  // Include Middleware
                  app.use(express.static(__dirname + '/public'))
                     .use(cors())
                     .use(cookieParser())
                     .use(express.json())
                     .use(express.urlencoded({ extended: true }))
                     require('dotenv').config()
                  
                     
                  
                  // Include all Models
                  app.use((req, res, next) => {
                    req.context = {
                      models,
                    };
                    next();
                  });
                  
                  
                  
                  // Load Routes from Router Index
                  app.use('/', routes);
                  
                  sequelize.sync().then(() => {
                    app.listen(process.env.PORT, () => {
                      console.log(`Example app listening on port ${process.env.PORT}!`)
                    });
                  });
                  

                  想法或指示?谢谢!

                  推荐答案

                  在 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 应用程序时导入目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Sequelize.js - “不关联到" 下一篇:Sequelize 按日期分组,不考虑小时/分钟/秒

                  相关文章

                  <small id='DqzIt'></small><noframes id='DqzIt'>

                  <tfoot id='DqzIt'></tfoot>
                  1. <i id='DqzIt'><tr id='DqzIt'><dt id='DqzIt'><q id='DqzIt'><span id='DqzIt'><b id='DqzIt'><form id='DqzIt'><ins id='DqzIt'></ins><ul id='DqzIt'></ul><sub id='DqzIt'></sub></form><legend id='DqzIt'></legend><bdo id='DqzIt'><pre id='DqzIt'><center id='DqzIt'></center></pre></bdo></b><th id='DqzIt'></th></span></q></dt></tr></i><div id='DqzIt'><tfoot id='DqzIt'></tfoot><dl id='DqzIt'><fieldset id='DqzIt'></fieldset></dl></div>

                    • <bdo id='DqzIt'></bdo><ul id='DqzIt'></ul>
                    <legend id='DqzIt'><style id='DqzIt'><dir id='DqzIt'><q id='DqzIt'></q></dir></style></legend>