【问题标题】:npm run server error '.' is not recognized as an internal or external command,npm 运行服务器错误“。”不被识别为内部或外部命令,
【发布时间】:2022-05-10 16:38:54
【问题描述】:

我在使用 angular 和 npm 时遇到了这个问题,但我还没有找到解决方案。我正在工作的项目是this angular project from github,这个确切的代码对其他人有用,所以问题可能出在我这边。

命令 npm run server 给出以下错误:

angular-course@0.0.0 服务器 ./server.ts

'.'未被识别为内部或外部命令,可操作 程序或批处理文件。

package.json 文件中的服务器脚本:

"server": "./node_modules/.bin/ts-node -P ./server.tsconfig.json ./server.ts"

我先运行了 npm install 命令,所有文件和依赖项都已成功安装,所以我不确定是什么问题。

【问题讨论】:

  • 你是在pc还是mac上运行这个?
  • Windows 10 - 电脑
  • 也许你使用的是旧的 nodejs 版本?
  • 我的节点版本是v14.16.0
  • 更新您的节点,检查系统中的路径,重新安装节点。也试试这个npm install -g ts-node

标签: angular npm npm-run


【解决方案1】:

我认为 / 本身存在问题,因此请将其替换为类似 .\\node_modules\\.bin\\ts-node -P ./server.tsconfig.json ./server.ts 的内容

【讨论】:

    【解决方案2】:

    此存储库似乎已过时。我有同样的问题。 为了解决此问题,请尝试以下命令: .\node_modules\.bin\ts-node -P .\server.tsconfig.json .\server.ts

    server.ts的内容如下:

    import * as express from 'express';
    import {Application} from 'express';
    import {getAllCourses} from './server/get-courses.route';
    import {saveCourse} from './server/save-course.route';
    
    
    const bodyParser = require('body-parser');
    
    const app: Application = express();
    
    app.use(bodyParser.json());
    
    app.route('/api/courses').get(getAllCourses);
    
    app.route('/api/courses/:id').put(saveCourse);
    
    
    
    const httpServer = app.listen(9000, () => {
        console.log('HTTP REST API Server running at http://localhost:' + httpServer.address().port);
    });
    
    

    【讨论】:

      猜你喜欢
      • 2021-11-30
      • 2018-10-19
      • 2018-12-25
      • 2019-01-25
      • 1970-01-01
      • 2018-11-01
      • 1970-01-01
      • 2018-07-13
      • 2018-01-10
      相关资源
      最近更新 更多