在 NPM 脚本中找不到模块自动前缀 [英] Cannot find module autoprefixer in NPM scripts

查看:108
本文介绍了在 NPM 脚本中找不到模块自动前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 windows 10 和 npm 版本 6.9.0 下,我无法使用以下脚本:

"build:css": "postcss --use autoprefixer -b 'last 2 versions' < ./static/css/main.css"

我总是在 Windows 控制台中遇到相同的错误,如下所示:

<块引用>

插件错误:找不到模块autoprefixer"

我尝试将语法更改为以下语法但没有结果:

"build:css": "postcss --use autoprefixer -b \"last 10 versions\" ./static/css/main.css -o ./静态/css/main-prefixed.css"

谁能告诉我这里有什么问题?老实说,我对这个 npm 脚本很陌生.

我的 package.json 看起来像这样:

{"name": "test-automate-npm","版本": "1.0.0","描述": "测试","main": "index.html",脚本":{"test": "echo \"Error: no test specified\" && exit 1","scss": "echo '编译 SCSS' && node-sass --watch scss -o ./static/css","build": "npm run scss && npm run build:css","build:css": "postcss --use autoprefixer -b 'last 2 versions' < ./static/css/main.css"},关键词":["关键词",这里"],"author": "Barleby","license": "ISC",依赖关系":{节点 sass":^4.12.0"},开发依赖":{"autoprefixer": "^6.3.1","postcss": "^5.0.16","postcss-cli": "^2.5.0"}}

先谢谢你!

<小时>

我还尝试在 package.json 中定义名为 build:css 的 npm 脚本,如下所示:

"build:css": "postcss ./static/css/main.css autoprefixer -b \"last 10 versions\" -o ./static/css/main-prefixed.css"

这会导致控制台打印出以下错误:

<块引用>

您没有设置任何插件、解析器或字符串化器.现在,PostCSS 什么都不做.在 postcss.parts 上为您的案例选择插件,并在 postcss.config.js 中使用它们.

解决方案

  1. 创建一个名为 postcss.config.js 的新文件,其中包含以下内容:

    module.exports = {插件:{自动前缀:{浏览器:['最近 10 个版本']}}};

    将新创建的postcss.config.js文件保存在你的项目根目录下,即保存在package.json所在的同一目录下.>

  2. package.json 中名为 build:css 的 npm 脚本更改为以下内容:

    ...脚本":{..."build:css": "postcss ./static/css/main.css -o ./static/css/main-prefixed.css"},...

Under windows 10 and npm version 6.9.0, I cannot get the following script to work:

"build:css": "postcss --use autoprefixer -b 'last 2 versions' < ./static/css/main.css"  

I'm always getting same error in the Windows console as follows:

Plugin Error: Cannot find module 'autoprefixer'

I've tried changing the syntax to the following one with no results:

"build:css": "postcss --use autoprefixer -b \"last 10 versions\" ./static/css/main.css -o ./static/css/main-prefixed.css"

Can anyone tell me whats the problem in here? Honestly, I'm quite new to this npm script.

My package.json looks like this:

{
  "name": "test-automate-npm",
  "version": "1.0.0",
  "description": "test",
  "main": "index.html",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "scss": "echo 'Compiling SCSS' && node-sass --watch scss -o ./static/css",
    "build": "npm run scss && npm run build:css",
    "build:css": "postcss --use autoprefixer -b 'last 2 versions' < ./static/css/main.css"   
  },
  "keywords": [
    "keywords",
    "here"
  ],
  "author": "Barleby",
  "license": "ISC",
  "dependencies": {
    "node-sass": "^4.12.0"
  },
  "devDependencies": {
    "autoprefixer": "^6.3.1",
    "postcss": "^5.0.16",
    "postcss-cli": "^2.5.0"
  }
}

Thank you in advance!


Edit:

I've also tried defining the npm script named build:css in package.json as follows:

"build:css": "postcss ./static/css/main.css autoprefixer -b \"last 10 versions\" -o ./static/css/main-prefixed.css"

and this results in the following error printed to the console:

You did not set any plugins, parser, or stringifier. Right now, PostCSS does nothing. Pick plugins for your case on postcss.parts and use them in postcss.config.js.

解决方案

  1. Create a new file named postcss.config.js that contains the following content:

    module.exports = {
      plugins: {
        autoprefixer: {
          browsers: ['last 10 versions']
        }
      }
    };
    

    Save the newly created postcss.config.js file in the root of your project directory, i.e. save it in the same directory where package.json resides.

  2. Change the npm script named build:css in your package.json to the following:

    ...
    "scripts": {
      ...
      "build:css": "postcss ./static/css/main.css -o ./static/css/main-prefixed.css"
    },
    ...
    

这篇关于在 NPM 脚本中找不到模块自动前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆