【问题标题】:''postcss' is not recognized as an internal or external command, operable program or batch file\'\'postcss\' 不是内部或外部命令,也不是可运行的程序或批处理文件
【发布时间】:2023-01-25 01:40:56
【问题描述】:

即使我安装了 postcss,当我尝试构建时,终端中仍然出现上述错误。我将它与 tailwindcss 结合使用,我的 postcss.config.js 文件如下所示:

module.exports = {
    plugins: [
        require('tailwindcss'),
        require('autoprefixer'),
        require('cssnano'),
    ]
}

我已经更新了所有包并清除了 NPM 缓存。我的任何其他构建都没有发生这种情况。我的 package.json 文件中可能有错误吗?这是其中的一部分:

"devDependencies": {
    "@wordpress/scripts": "^19.2.2",
    "dir-archiver": "^1.1.1",
    "node-sass": "^7.0.1",
    "postcss-cli": "^9.1.0",
    "rtlcss": "^3.5.0"
  },
  "rtlcssConfig": {
    "options": {
      "autoRename": false,
      "autoRenameStrict": false,
      "blacklist": {},
      "clean": true,
      "greedy": false,
      "processUrls": false,
      "stringMap": []
    },
    "plugins": [],
    "map": false
  },
  "scripts": {
    "build": "postcss css/styles.css -o build/styles.css",
    "watch": "node-sass sass/ -o ./ --source-map true --output-style expanded --indent-type tab --indent-width 1 -w",
    "compile:css": "node-sass sass/ -o ./ && stylelint '*.css' --fix || true && stylelint '*.css' --fix",
    "compile:rtl": "rtlcss style.css style-rtl.css",
    "lint:scss": "wp-scripts lint-style 'sass/**/*.scss'",
    "lint:js": "wp-scripts lint-js 'js/*.js'",
    "bundle": "dir-archiver --src . --dest ../_s.zip --exclude .DS_Store .stylelintrc.json .eslintrc .git .gitattributes .github .gitignore README.md composer.json composer.lock node_modules vendor package-lock.json package.json .travis.yml phpcs.xml.dist sass style.css.map yarn.lock"
  },
  "main": "index.js",
  "dependencies": {
    "autoprefixer": "^10.4.4",
    "gsap": "^3.11.4",
    "npm-check-updates": "^16.6.2",
    "postcss": "^8.4.21",
    "swiper": "^8.4.6",
    "tailwindcss": "^3.2.4"
  }

【问题讨论】:

    标签: node.js npm tailwind-css postcss postcss-cli


    【解决方案1】:

    npm 将 dependenciesdevDependencies 安装到 node_modules 中,这是非常稀有在你的路径中。 Node 附带了一个有用的命令 npx,它可以用 npx postcss 为您执行此操作。 package.json 中的脚本在其 PATH 中使用 node_modules/.bin 运行,因此我还会检查您是否正在运行 npm run build 而不仅仅是 postcss 命令。否则,只需全局安装它。

    【讨论】:

    • 谢谢你的信息。当我运行 npx postcss 时,出现以下错误:npm ERR!无法确定要运行的可执行文件。我也在用npm run build
    • 全局安装 postcss 就可以了
    • @CiaranGaffey 如果这个答案有帮助,请您打勾左边的复选标记,以便将来更容易为其他人找到?如果您解决了自己的问题,请随时添加您自己的答案并接受它。
    猜你喜欢
    • 2023-01-25
    • 2023-01-19
    • 2022-12-06
    • 2023-02-26
    • 1970-01-01
    • 2022-11-23
    • 2018-08-25
    • 2014-06-01
    • 2022-01-06
    相关资源
    最近更新 更多