question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

“unexpected keyword 'import'” error

See original GitHub issue

I have recently made a change to a SCSS file which contains @import "./fonts.scss"; at the top. My actual changes were further down the file as I was editing some styling. As part of the pre-commit git hook with Husky, it checks changed files.

When I commit, i get the error message:

Stylelint found some errors. Please fix them and try committing again. Unexpected keyword ‘import’

File changed and referenced in error above

public/style.scss file:

// unchanged here, just part of linting entire file
@import "./fonts.scss";
@import "./info.scss";
@import "./item.scss";

// actual changes made below:
.class-style {
  color: red;
}

.stylintrc file config:

{
  "processors": [
    "stylelint-processor-styled-components"
  ],
  "extends": [
    "stylelint-config-recommended",
    "stylelint-config-styled-components"
  ],
  rules: {
    "block-no-empty": null,
    "font-family-no-missing-generic-family-keyword": null
  }
}

lintstagedrc file:

{
  "*.scss": [
    "stylelint --syntax=scss",
    "prettier --write",
    "git add"
  ],
  "*.css.js": [
    "prettier --write",
    "git add"
  ],  
  "*.js": [
    "eslint --fix",
    "prettier --write",
    "git add"
  ]
}

I tried also installing stylelint-config-recommended-scss and stylelint-scss as recommended, but that did not fix it.

I tried to disable the stylelint-config-styled-components extends plugin, but then I get an error of “Unexpected empty-source”

I appreciate any insight.

EDIT: I should have noted that this is a mono-repo. We have a main folder with project sub folders.

root
|_ .eslintrc (base settings)
|_ .lintstagedrc
|_ .stylelintrc (base settings)
|_ .prettierrc
|__project1
    |_ .eslintrc (project specific settings)
    |_ .prettierrc
|__project2
    |_ .eslintrc (project specific settings)
    |_ .prettierrc

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

1reaction
JoaquimEstevescommented, Mar 14, 2021

I’m also facing this issue.

My current solution is similar to chadlof’s, basically setup two different config and run the linting separately.

"lint:css": "stylelint src_with_scss/ --config path1 && stylelint src_with_styled/ --config path2",

Here’s a link to a more detailed explanation

This is…inelegant to say the least! But it looks like the folks that are handling the styled-components processor say that it’s basically impossible to have both.

1reaction
luckspcommented, Aug 11, 2020

OK! I have replicated this. I think this relates to having a combo of SCSS & Styled (*.css.js) JS files being linted at the same time when processor: "stylelint-processor-styled-components" is used.

How can I break up/apart SCSS & Styled logic?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parsing error: Unexpected keyword 'import' #12752 - GitHub
Parsing error: Unexpected keyword 'import' #12752. Closed. simkessy opened this issue on Jan 6, 2020 · 2 comments.
Read more >
Unexpected keyword 'import' in vue project [closed]
... like import axios from 'axios' it returns this error Unexpected keyword 'import' after that i imported it in my main.js file but...
Read more >
list of example YANG data modules
YANG Model Draft Name Email Compil... example‑barmod.yang draft‑ietf‑core‑yang‑cbor‑10.txt Email Authors FAILED example‑bfd‑echo.yang draft‑ietf‑bfd‑yang‑17.txt Email Authors PASSE... example‑bridge.yang draft‑vassilev‑netmod‑network‑bridge‑02.txt Email Authors FAILED
Read more >
[Solved]-Unexpected keyword 'import' in vue project-Vue.js
Coding example for the question Unexpected keyword 'import' in vue project-Vue.js. ... This error is produced by the linter in your project:
Read more >
[Haskell-beginners] A question about import
Hi, when I try to use import like these: import System.Random import Control.Monad I get this error: "Syntax error in input (unexpected keyword...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found