簡體   English   中英

angularjs TypeError:require(...)不是函數,nodejs運行錯誤

[英]angularjs TypeError: require(…) is not a function , nodejs run error

我采取一個非常類似的代碼,發現這里

當我運行節點web.js時,我得到一個TypeError:require(...)不是一個函數
為什么我會得到這樣的錯誤? 問題出在哪兒?

這是我的web.js

var express = require('express');

var apiFiles = './backend';
var wwwFiles = './app';

require(apiFiles + '/api')(function(backend) {
  var www = express.static(wwwFiles);
  express()
    .use('/api', backend)
    .use('/', www)
    .listen(process.env.PORT || 3000);
});

這是我的文件夾結構:
在此輸入圖像描述

最終目標是將其部署到heroku。

看起來你缺少requireJSexpress

在require語句正上方添加此行 - console.log('require');

如果它傳入一個函數,那么只需運行npm install --save express (或express@whatever-version-you-want

否則,您可能需要重新設置應用程序。 我很確定requireJS是節點核心的一部分。

在tsconfig.json中,如果將“module”設置為“system”,請嘗試將其更改為“commonjs”。 這對我有用。

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceRoot": "./client",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false
    },
    "exclude": [
        "../node_modules",
        "../typings/main",
        "../typings/main.d.ts"
    ]
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM