当我尝试启动 azure 应用程序时如何修复 ERR

编程入门 行业动态 更新时间:2024-10-09 16:29:32

<a href=https://www.elefans.com/category/jswz/34/1771369.html style=当我尝试启动 azure 应用程序时如何修复 ERR"/>

当我尝试启动 azure 应用程序时如何修复 ERR

我已经在azure中部署了我的节点应用程序,但是我不知道如何解决这个错误:

应用程序抛出未捕获的异常并被终止:Error [ERR_REQUIRE_ESM]: ES Module C:\home\site\wwwroot pp.js 的require() 来自 C:\Program Files (x86)\iisnode\interceptor.js 不是 支持。改为更改 C:\Program Files 中 app.js 的要求 (x86)\iisnode\interceptor.js 到可用的动态 import() 所有 CommonJS 模块中的 .at 对象。 (C:\Program 文件 (x86)\iisnode\interceptor.js:459:1)

所有解决方案都说明我必须添加

“类型”:“模块”

在 package.json 文件中更改需要导入,但我已经这样做了。 另外,我找不到这个 iisnode 文件夹,也找不到 interceptor.js 文件。

我按照本指南部署我的应用程序:;pivots=development-environment-vscode

package.json

{
  "name": "my-express-app",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node app.js"
  },
  "type": "module",
  "description": "my-express-app",
  "author": {
    "name": ""
  },
  "dependencies": {
    "@azure/msal-node": "^1.16.0",
    "axios": "^1.3.4",
    "body-parser": "^1.15.0",
    "cookie-parser": "^1.4.0",
    "cors": "^2.8.5",
    "dotenv": "^16.0.3",
    "express": "^4.14.0",
    "morgan": "^1.7.0",
    "nodemon": "^2.0.20",
    "pug": "^3.0.2",
    "serve-favicon": "^2.3.0",
    "tedious": "^15.1.2",
    "tedious-connection-pool": "^1.0.5"
  }
}

app.js

import express from "express";
import logger from "morgan";
import cookieParser from "cookie-parser";
import bodyParser from "body-parser";
import * as checkResource from "./middleware/checkResource.js";
import { setError } from "./middleware/error.js";
import cors from "cors";

import { router as routes_Admin } from "./controllers/admin.js";
import { resolve } from "path";

export var app = express();

// middlewares
app.use(checkResource.check);
app.use(setError);
app.use("/static", express.static("public"));
app.use(express.json());
app.use(cors());

//controllers;
app.use(routes_Admin);

app.use(logger("dev"));

app.use(bodyParser.json());
app.use(cookieParser());

app.set("port", process.env.PORT || 3000);

app.get("/", (req, res) => {
  console.log("Hello World!");
  res.send("Hello world!");
});

app.listen(app.get("port"), () => {});

web.config

<?xml version="1.0" encoding="utf-8"?>
<!--
     This configuration file is required if iisnode is used to run node processes behind
     IIS or IIS Express.  For more information, visit:
     .config
-->

<configuration>
  <system.webServer>
    <!-- Visit .aspx for more information on WebSocket support -->
    <webSocket enabled="false" />
    <handlers>
      <!-- Indicates that the app.js file is a node.js site to be handled by the iisnode module -->
      <add name="iisnode" path="app.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>
        <!-- Do not interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^app.js\/debug[\/]?" />
        </rule>

        <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
        <rule name="StaticContent">
          <action type="Rewrite" url="{REQUEST_URI}"/>
        </rule>

        <!-- All other URLs are mapped to the node.js site entry point -->
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="app.js"/>
        </rule>
      </rules>
    </rewrite>
    
    <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
        </hiddenSegments>
      </requestFiltering>
    </security>

    <!-- Make sure error responses are left untouched -->
    <httpErrors existingResponse="PassThrough" />

    <!--
      You can control how Node is hosted within IIS using the following options:
        * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
        * node_env: will be propagated to node as NODE_ENV environment variable
        * debuggingEnabled - controls whether the built-in debugger is enabled
      See .config for a full list of options
    -->
    <!--<iisnode watchedFiles="web.config;*.js"/>-->
  </system.webServer>
</configuration>
回答如下:

更多推荐

当我尝试启动 azure 应用程序时如何修复 ERR

本文发布于:2024-05-13 15:02:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1759776.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:当我   应用程序   azure   ERR

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!