【问题标题】:Cant build app using npx grunt on Windows无法在 Windows 上使用 npx grunt 构建应用程序
【发布时间】:2020-05-01 08:32:14
【问题描述】:

在 Windows 8.1 上安装了 Node.js 12.16。

首先我在项目的根目录中运行“npm install grunt”。

安装成功,但出现以下警告:

 npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@
 1, but npm-shrinkwrap.json was generated for lockfileVersion@0. I'll try to do m
 y best with it!
 npm WARN deprecated minimatch@0.2.14: Please update to minimatch 3.0.2 or higher
 to avoid a RegExp DoS issue
 npm WARN deprecated coffee-script@1.3.3: CoffeeScript on NPM has moved to "coffe
 escript" (no hyphen)
 npm WARN deprecated minimatch@0.3.0: Please update to minimatch 3.0.2 or higher
 to avoid a RegExp DoS issue
 npm WARN platform-web@0.0.1 No repository field.
 npm WARN platform-web@0.0.1 No license field.
 npm WARN The package time-grunt is included as both a dev and production depende
 ncy.
 npm WARN The package object-assign is included as both a dev and production depe
 ndency.

+ grunt@0.4.5
added 38 packages from 47 contributors and audited 54 packages in 3.026s
found 25 vulnerabilities (5 low, 6 moderate, 14 high)
run `npm audit fix` to fix them, or `npm audit` for details

根目录包含 grunt-folder (root_dir/grunt),其中包含 Gruntfile.js 和 package.json 文件。

这个 grunt-folder 包含其他 grunt-folder (root_dir/grunt/grunt)。第二个 grunt 包含一些 js 文件。

然后在“root_dir/grunt”中运行“npx grunt”。但是构建中止了以下日志:

>> Local Npm module "grunt-contrib-clean" not found. Is it installed?
>> Local Npm module "grunt-contrib-copy" not found. Is it installed?
>> Local Npm module "grunt-includes" not found. Is it installed?
>> Local Npm module "grunt-text-replace" not found. Is it installed?
>> Local Npm module "grunt-contrib-concat" not found. Is it installed?
>> Local Npm module "grunt-contrib-uglify" not found. Is it installed?
>> Local Npm module "grunt-contrib-cssmin" not found. Is it installed?
>> Local Npm module "grunt-file-creator" not found. Is it installed?
>> Local Npm module "grunt-war" not found. Is it installed?
>> Local Npm module "nexus-deployer" not found. Is it installed?

Warning: Task "clean:all" not found. Use --force to continue.

Aborted due to warnings.

package.json 是

{
   "name": "platform-web",
   "version": "0.0.1",
   "description": "Platform",
   "devDependencies": {
   "archiver": "^0.12.0",
   "grunt": "^0.4.5",
   "grunt-contrib-clean": "^0.6.0",
   "grunt-contrib-concat": "^0.5.1",
   "grunt-contrib-copy": "^0.8.0",
   "grunt-contrib-cssmin": "0.12.3",
   "grunt-contrib-uglify": "^0.6.0",
   "grunt-file-creator": "^0.1.3",
   "grunt-includes": "^0.5.1",
   "grunt-text-replace": "^0.4.0",
   "grunt-war": "^0.5.1",
   "nexus-deployer": "^0.1.8",
   "object-assign": "^4.0.1",
   "time-grunt": "^1.1.0"
 },
  "dependencies": {
   "time-grunt": "^1.0.0",
   "object-assign": "^4.0.1"
    }
}

我做错了什么?

ps:根文件夹是:

【问题讨论】:

  • 你能分享你的“package.json”文件吗?您必须将所有“grunt-*”+“nexus-deployer”库安装为开发依赖项。
  • 您在运行“npm install grunt”之前是否运行过“npm install”?此外,使用“npx grunt-cli”而不是“npx grunt”运行 grunt CLI
  • 我运行“npm install”和“npx grunt-cli”。我仍然收到“中止...”。但我有一些进展:dist-folder 出现在 grunt-folder 中。 “dist”的出现是构建阶段的成功标准(基于工作项目文档)

标签: node.js gruntjs


【解决方案1】:

只有旧版本的 grunt 才需要以下内容。新的可以正确安装 bunstubbs,所以你仍然可以通过 npm 而不是全局安装 grunt。

安装 grunt-cli。这将正确选择项目正在运行的任何版本的 grunt 并执行它。

npm install grunt-cli --save-dev

在 package.json 中将 dev 脚本更改为

"scripts": {
    "start": "npx grunt-cli"
  }

然后运行

npm run start

【讨论】:

    猜你喜欢
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 2022-10-20
    相关资源
    最近更新 更多