Skip to content

creating sass components #900

Closed
Closed

Description

@uptownhr

Hi, first time trying out bitsrc and running into a problem creating a sass component. I'm creating a sass component that currently depends on the bulma node_modules package. In my sass file i am importing bulma as so,

@import '~bulma/sass/utilities/_all.sass';

The issue is that sass using the tilda as a resolver to link to packages in node_modules but bitsrc does not recognize this.

Any workarounds here?

Expected Behavior

Able to import using sass ~ alias to load in files from node_modules packages

Actual Behavior

Errors out saying ~package-name is unavailable
image

Steps to Reproduce the Problem

  1. create sass files
  2. in the sass file import a sass file from a node modules package using @import ~ syntax
  3. notice the dependecy error

Specifications

  • Bit version: 0.12.11
  • Node version: 8.8.1
  • npm / yarn version: 5.6.0
  • Platform: ubuntu 16.04
  • Bit compiler (include version): na
  • Bit tester (include version): na

Activity

  1. davidfirst commented on Apr 26, 2018

    @davidfirst
    Member

    Seems like the issue comes from the 'detective-sass' library.
    It fails to parse the line with the 'import' statement. You can easily see it happening when adding "DEBUG=*" before the command.
    Here is what I get from detective-sass:

    detective-sass content: @import "~bulma/sass/utilities/_all.sass"; +0ms
    detective-sass parse error: Please check validity of the block starting from line #1 +9ms

    I tried working with this package solely and I get the same parse error.
    @uptownhr if you can post the issue in the detective-sass Github repo, it'd be great.

    As to the tilda, Bit actually supports it. (See the specific code here. )

  2. uptownhr commented on Apr 27, 2018

    @uptownhr
    Author

    Hmm thanks for that. Looking at https://github.com/teambit/bit-javascript/blob/master/src/dependency-builder/filing-cabinet/index.js#L51, can we add '.scss' to this list? My files are written in scss, and explains the problem :).

  3. added a commit that references this issue on May 6, 2018
  4. itaymendel commented on Aug 23, 2018

    @itaymendel
    Contributor

    closing this issue as the matter was handled in the issue david closed about a month ago

  5. cj commented on Sep 17, 2018

    @cj

    @itaymendel I just run into this exact issue using bit-bin v13.0.4, has support for this not been merged in yet?

  6. davidfirst commented on Sep 20, 2018

    @davidfirst
    Member

    @cj , part of this issue has been fixed recently on #1215.
    This part has not been merged yet.

  7. javed74 commented on Dec 8, 2018

    @javed74

    @davidfirst - I am also facing same issue. Any idea when this fix will be released? (I am using v13.0.4)

  8. mrdoinel commented on Jan 25, 2019

    @mrdoinel

    I am getting the same issue when trying to import a SCSS file into my vue component.

    At the end of my Button.vue

    <style lang="scss" scoped>
      @import '~@/style.scss';
    </style>
    

    bit status

    components/button
    missing packages dependencies (use your package manager to make sure all package dependencies are installed):
         src/components/Button.vue -> ~@
    

    The content of my bit.json :

    {
        "env": {
            "compiler": "bit.envs/bundlers/[email protected]"
        },
        "dependencies": {},
        "componentsDefaultDirectory": "components/{namespace}/{name}",
        "packageManager": "npm",
        "resolveModules": {
            "modulesDirectories": [
                "src/components"
            ],
            "aliases": {
                "@": "src/components"
            }
        }
    }
    

    I am using v13.0.4.

  9. mrdoinel commented on Jan 25, 2019

    @mrdoinel

    For those who are getting the same issue, it is working if the path is relative (which is a bit annoying) :

    @import '../components/style.scss';

    <style lang="scss" scoped>
      @import '../components/style.scss';
    
  10. mathieuartu commented on Jun 13, 2019

    @mathieuartu

    What's the status on this? I'd like to import scss files without using the relative path...

  11. davidfirst commented on Jun 14, 2019

    @davidfirst
    Member

    Another fix related to this issue has been done two weeks ago here: teambit/bit-javascript#100.
    The current version, v14.1.3 has it all fixed.

    I'll explain it as it is not trivial.
    There are two main cases here.

    Case 1: there is a match with resolveModules.aliases settings

    For example, your scss file has import '~scss/styles.scss'; and your workspace config has resolveModules.aliases: { "~scss": "src/scss" }
    Bit will use the resolveModule setting, regardless of whether it has a slash after the Tilda (~/) or not (~).
    In the example above, it'll resolve the dependency to src/scss/styles.scss.
    Same thing if your dependency is import '~/scss/styles.scss'; and your workspace config has resolveModules.aliases: { "~/scss": "src/scss" }, it will not try to resolve to node_modules, because you have your custom resolve settings.

    Case 2: there is no match with resolveModules.aliases settings

    Whether you didn't configure anything or your configuration doesn't match the current import statement.
    Bit uses the Webpack Sass Loader settings here, which states that ~/ (e.g. ~/bootstrap) resolves to a local file, but ~ (e.g. ~bootstrap) resolves to the node_modules.
    In their words:

    webpack provides an advanced mechanism to resolve files. The sass-loader uses Sass's custom importer feature to pass all queries to the webpack resolving engine. Thus you can import your Sass modules from node_modules. Just prepend them with a ~ to tell webpack that this is not a relative import:

    @import "~bootstrap/dist/css/bootstrap";
    It's important to only prepend it with ~, because ~/ resolves to the home directory. webpack needs to distinguish between bootstrap and ~bootstrap because CSS and Sass files have no special syntax for importing relative files. Writing @import "file" is the same as @import "./file";

    https://github.com/webpack-contrib/sass-loader

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions