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.

Importing sass from node_modules with vue plugin

See original GitHub issue

Hello! I’m trying to use vue plugin and importing sass from node_modules there with ‘~’ syntax. It’s important for me to use that syntax and not relative ‘./node_modules/…’ because the component is a part of the library and I want it to be importable as a .vue file (along with bili build).

<template>
  <a class="button is-primary">Button</a>
</template>

<script>
module.exports = {
  name: 'button-example',
};
</script>

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

When I’m running bili on that file I get the error:

⋊> ~/p/bili-sass-import-tilde-example npm run build                              12:51:03

> bili-sass-import-tilde-example@0.1.0 build /home/larionov/projects/bili-sass-import-tilde-example
> bili --plugins.vue --format=cjs,esm,umd --module-name=Example

error Failed to bundle src/index.js in cjs format

Stack Trace:
Error: Error: File to import not found or unreadable: ~bulma/bulma.
    at Promise.all.descriptor.styles.map (/home/larionov/projects/bili-sass-import-tilde-example/node_modules/rollup-plugin-vue/dist/rollup-plugin-vue.js:241:31)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bili-sass-import-tilde-example@0.1.0 build: `bili --plugins.vue --format=cjs,esm,umd --module-name=Example`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the bili-sass-import-tilde-example@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/larionov/.npm/_logs/2019-03-22T05_51_07_306Z-debug.log

Here is a minimal repository where the error can be reproduced: https://github.com/larionov/bili-vue-sass-import-tilde-example

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
larionovcommented, Mar 22, 2019

We went with magic-importer: bili.config.js

import path from 'path';
import magicImporter from 'node-sass-magic-importer';

const config = {
  plugins: {
    vue: {
      style: {
        preprocessOptions: {
          scss: {
            importer: magicImporter(),
          },
        },
      },
    },
  },
};

export default config;
2reactions
egoistcommented, Mar 22, 2019

You can use https://rollup-plugin-vue.vuejs.org/options.html#style-preprocessoptions to set sass options, ~ is implemented in rollup-plugin-postcss via the importer option: https://github.com/egoist/rollup-plugin-postcss/blob/e63c9ae659fe4e982fa8d31c955767c2a5e6e98f/src/sass-loader.js#L38

I’ll try to make bili support this by default, not anytime soon though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add sass loader for node_modules in vue.config.js
Try this, from the docs: @import "~my-node-module/theme/engine.scss";. The ~ tells Webpack that the import path is not a relative path.
Read more >
Using Pre-Processors - Vue Loader
Now in addition to being able to import 'style.scss' , we can use SCSS in Vue ... if you import a Vue SFC...
Read more >
sass-loader - webpack - JS.ORG
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...
Read more >
Getting Started | BootstrapVue
import Vue from 'vue' import { BootstrapVue, IconsPlugin } from ... SCSS files (order is important) @import 'node_modules/bootstrap/scss/bootstrap.scss'; ...
Read more >
Bootstrap & Vite
Set up Bootstrap's Sass import in vite.config.js . ... You can also import JavaScript plugins individually as needed to keep bundle sizes down:....
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