English 中文(简体)
npm 将启动: dev on NestJS 应用程序
原标题:npm won t start:dev on NestJS application

于是我用 CLI 创建了一个新的 < code> NestJS 应用程序。 我安装了 < code> nodemon , 作为一种依赖性并在全球范围内。 我的 < code> package.json 看起来像 :

"scripts": {
"build": "tsc -p tsconfig.build.json",
"format": "prettier --write "src/**/*.ts"",
"start": "ts-node -r tsconfig-paths/register src/main.ts",
"start:dev": "nodemon",
"start:debug": "nodemon --config nodemon-debug.json",

我的 nodemon.json 看起来像这个:

"watch": ["src"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node -r tsconfig-paths/register src/main.ts"

如此基本的设置。 但如果我尝试这样启动 dev 服务器 : npm start: dev , 我就会收到此错误消息 :

Usage: npm < command >

where < command > is one of:

access, adduser, audit, bin, bugs, c, cache, ci, cit,
clean-install, clean-install-test, completion, config,
create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
edit, explore, get, help, help-search, hook, i, init,
install, install-ci-test, install-test, it, link, list, ln,
login, logout, ls, org, outdated, owner, pack, ping, prefix,
profile, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, team, test, token, tst, un,
uninstall, unpublish, unstar, up, update, v, version, view,
whoami

Specify configs in the ini-formatted file: /Users/XXXXX/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

[email protected] /usr/local/lib/node_modules/npm

Did you mean this?
    start

我的 npmrc 包含一些我工作上 的 gitub repo 证书!

最佳回答

要运行 npm 脚本, 您必须调用 < code> npm run 。 所以调用 < code> npm run start: dev

问题回答

仅对 Nodejs 使用 Nodimon 。 在 Nestjs 中, 要使用热重新装入, 需要做以下操作 :

STEP1: 首先安装所需的包件 :

 npm i --save-dev webpack-node-externals run-script-webpack-plugin webpack

STEP2: 在您应用程序的根目录中创建 < strong> webpack- hmr.config.js 文件

添加代码 :

const nodeExternals = require( webpack-node-externals );
const { RunScriptWebpackPlugin } = require( run-script-webpack-plugin );

module.exports = function (options, webpack) {
  return {
    ...options,
    entry: [ webpack/hot/poll?100 , options.entry],
    externals: [
      nodeExternals({
        allowlist: [ webpack/hot/poll?100 ],
      }),
    ],
    plugins: [
      ...options.plugins,
      new webpack.HotModuleReplacementPlugin(),
      new webpack.WatchIgnorePlugin({
        paths: [/.js$/, /.d.ts$/],
      }),
      new RunScriptWebpackPlugin({ name: options.output.filename, autoRestart: false }),
    ],
  };
};

STEP3: 为了启用高管关系系统,打开应用程序条目文件(main.ts ),并添加以下与网页包有关的说明:

declare const module: any;

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(3000);

  if (module.hot) {
    module.hot.accept();
    module.hot.dispose(() => app.close());
  }
}
bootstrap();

< 加固> STEP4: 要简化执行过程, 请在您的软件包.json 文件中添加脚本 。

"start:dev": "nest build --webpack --webpackPath webpack-hmr.config.js --watch"

<% 1> STEP5: 现在只需打开命令行并运行以下命令 :

 npm run start:dev

<强度>STEP6: 最终 Ctrl+S 到热装入





相关问题
Trying to install Flowise and npm cannot find it

On the https://flowiseai.com/ website, it says that all I have to do to use flowise is the following: npm install -g flowise npx flowise start However, when I try to do the install, it doesn t work....

Cannot destructure property name of node as it is null

when I want to install dependencies of the aurelia project, got this error: npm ERR! code 1 npm ERR! git dep preparation failed npm ERR! command /Users/ehsanghaffarii/.nvm/versions/node/v15.5.1/bin/...

npm install issues on Ubuntu 9.04

I’m trying to install npm using the commands from here: http://howtonode.org/introduction-to-npm Specifically, when I run: curl http://npmjs.org/install.sh | sh This is the error I get... node cli....

热门标签