postcss / postcss-cli

CLI for postcss
Other
840 stars 93 forks source link

Errors when trying to parse sourcemap files #249

Closed QSSRobert closed 6 years ago

QSSRobert commented 6 years ago

postcss seems to be trying to parse a .css.map file as css and breaking as a result.

Here's my directory structure:

_build/
  |- postcss.config.js
_src/
  |- sass/
        |-main.scss
css/
  |-main.css
  |-main.css.map
package.json

and postcss.config.js

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

and finally my package.json, the relevent npm script is build:autoprefix-css

{
  "name": "workflow",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build:css": "node-sass --source-map true ./_src/sass/ -o ./css",
    "build:autoprefix-css": "postcss --config ./_build/ -m -r ./css"
  },
  "license": "ISC",
  "browserslist": [
    "IE 11",
    "last 3 versions",
    "not IE < 11"
  ],
  "devDependencies": {
    "autoprefixer": "^9.3.1",
    "node-sass": "^4.10.0",
    "postcss": "^7.0.5",
    "postcss-cli": "^6.0.1"
  }
}

I then get the error

CssSyntaxError: D:\workflow\css\main.css.map:3:20: Missed semicolon

  1 | {
  2 |   "version": 3,
> 3 |   "file": "main.css",
    |                     ^
  4 |   "sources": [
  5 |           "../_src/sass/main.scss",

Of course, I could be doing something silly in my script, but if I am I can't for the life of me figure out what it is.

RyanZim commented 6 years ago

You're passing in simply a directory name, and postcss-cli is trying to process all the files in the directory, just as you told it to do. If your directory contains non-css files, you'll want to use a glob, like css/*.css instead of just the directory name.