【问题标题】:VS 2019 gruntfile.js no tasks found when using 'sass = require('node-sass')'VS 2019 gruntfile.js 使用 'sass = require('node-sass')' 时找不到任务
【发布时间】:2020-02-04 00:26:15
【问题描述】:

我第一次尝试在新的 .Net Core 3.1 Web 应用程序上设置 grunt-sass。我已经完成了 MSFT 的步骤,将 grunt 添加到此处概述 here 的项目中,然后使用 grunt-sass 指令 here 中的步骤对其进行了修改。

然而,这会导致任务运行器资源管理器声明没有找到任务。 这是我的 package.json:

{
  "name": "chapelstudios_www",
  "version": "0.0.2",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://me@bitbucket.org/me/chapelstudios_www.git"
  },
  "author": "mr",
  "license": "ISC",
  "homepage": "https://bitbucket.org/me/chapelstudios_www#readme",
  "private": true,
  "devDependencies": {
    "grunt": "^1.0.4",
    "grunt-cli": "^1.3.2",
    "grunt-sass": "^3.1.0",
    "node-sass": "^4.13.1"
  },
  "dependencies": {
    "gulp": "^4.0.2"
  }
}

这是我的 gruntfile.js:

const sass = require('node-sass');
require('load-grunt-tasks')(grunt);

module.exports = function (grunt) {
    // Project configuration.
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        // Sass
        sass: {
            options: {
                implementation: sass,
                sourceMap: true, // Create source map
                outputStyle: 'compressed' // Minify output
            },
            dist: {
                files: [
                    {
                        expand: true, // Recursive
                        cwd: "Styles", // The startup directory
                        src: ["**/*.scss"], // Source files
                        dest: "wwwroot/css", // Destination
                        ext: ".css" // File extension
                    }
                ]
            }
        }
    });

    // Load the plugin
    grunt.loadNpmTasks('grunt-sass');

    // Default task(s).
    grunt.registerTask('default', ['sass']);
};

我不确定如何获得更详细的错误信息,但已将问题追踪到

const sass = require('node-sass');

grunt-sass 指令所需的行。如果我将其更改为旧教程推荐的字符串“sass”,则任务会显示,但在我尝试实际运行它时会失败。

我还从项目目录中提升的 powershell 窗口运行了以下安装,以确保它们已安装到本地项目中,因为我听说这是一个主要问题:

npm install
npm install grunt
npm install grunt-cli
npm install --save-dev node-sass grunt-sass

在这一点上,我没有想法,但我是新手,所以我确定我错过了一些明显的东西。

【问题讨论】:

  • 我也有类似的问题。我正在使用 Visual Studio for Mac 并安装了任务资源管理器。但是我总是得到错误: Failed to load /Users/xxxx/Developer/Projects/xxx/xxx/Gruntfile.js ApplicationName='grunt', CommandLine='--no-color --tasks "/Users/xxxx/Library /Application Support/VisualStudio/8.0/LocalInstall/Addins/MonoDevelop.TaskRunnersBundle.0.1/GruntScript" md-grunt-task-list', CurrentDirectory='/Users/xxxx/Developer/Projects/xxx/xxx', Native error= 不能找到指定的文件
  • 这个问题解决了吗?

标签: gruntjs visual-studio-2019 node-sass .net-core-3.1 grunt-sass-lint


【解决方案1】:

对于使用现有项目访问此项目的其他任何人,我在新计算机上遇到了与预先存在的 node-sass / grunt 文件有关的问题,我发现我的包中的 node-sass 版本出现了问题。 json 导致 VS 重新安装软件包并更新绑定,如另一个答案中所述。

我有点怀疑在我的命令提示符下运行 grunt 和 VS 使用的任何版本之间存在版本差异,因为如果我手动运行我的 grunt 文件就可以正常工作,但不会显示在 Task Runner Explorer 中。

【讨论】:

    【解决方案2】:

    恢复一个老话题,但这对我有用。 YMMV。

    • 在 Visual Studio 中,转到:工具 -> 选项 -> Web 包管理 -> 外部网络工具。
    • 将 $(PATH) 移到 $(VSInstalledExternalTools) 上方。

    我不知道这样做是否有任何副作用。

    感谢:https://developercommunity.visualstudio.com/solutions/314606/view.html

    【讨论】:

      【解决方案3】:

      我发现以下错误导致我进行了重建:

      Error: Missing binding A:\Projects\Repos\chapelstudios_www\node_modules\node-sass\vendor\win32-x64-79\binding.node
      Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 13.x
      
      Found bindings for the following environments:
        - Windows 64-bit with Node.js 10.x
      
      This usually happens because your environment has changed since running `npm install`.
      Run `npm rebuild node-sass` to download the binding for your current environment.
      

      【讨论】:

        【解决方案4】:

        正如 Jake 所说,我也将错误跟踪到了这一行:

        const sass = require('node-sass');
        

        运行重建不起作用。我发现在升级节点从版本 10.x 到当前版本(12.18 Windows)然后重建解决了这个问题。

        npm rebuild node-sass
        

        【讨论】:

          猜你喜欢
          • 2015-02-13
          • 2017-04-12
          • 2022-06-16
          • 2017-01-12
          • 2020-05-07
          • 1970-01-01
          • 2019-11-29
          • 2020-09-08
          • 2021-08-20
          相关资源
          最近更新 更多