Skip to content

relative paths in SCSS cause ModuleNotFoundError #5633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
diachedelic opened this issue Jun 30, 2020 · 4 comments
Closed

relative paths in SCSS cause ModuleNotFoundError #5633

diachedelic opened this issue Jun 30, 2020 · 4 comments

Comments

@diachedelic
Copy link

Version

4.4.6

Reproduction link

https://github.com/diachedelic/vue-cli-scss-repro

Environment info

Environment Info:

  System:
    OS: macOS 10.15.5
    CPU: (4) x64 Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz
  Binaries:
    Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.5 - ~/.nvm/versions/node/v12.16.1/bin/npm
  Browsers:
    Chrome: 83.0.4103.116
    Edge: Not Found
    Firefox: Not Found
    Safari: 13.1.1
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

git clone [email protected]:diachedelic/vue-cli-scss-repro.git &&
  cd vue-cli-scss-repro &&
  ./build.sh

Also see this diff with the scaffolded app.

What is expected?

vue-cli-service build should succeed

What is actually happening?

 ERROR  Failed to compile with 1 errors                                                   2:08:52 PM

 error  in ./src/App.vue?vue&type=style&index=0&lang=scss&

Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleNotFoundError: Module not found: Error: Can't resolve './assets/image.svg' in '/private/tmp/vue-cli-scss-repro/vue-app/src'

Relative paths to assets in SASS should be resolved relative to the SCSS file, regardless of whether it is in the same module as the Vue CLI app. You can see in vanilla-app, which does not use the vue-cli, that the asset is resolved.

@diachedelic
Copy link
Author

I am trying to fix this but I do not know where to look. Does this seem like a bug in vue-loader? It seems like a problem in the way single file components import their SCSS and pass it on to webpack.

@diachedelic
Copy link
Author

@fangbinwei
Copy link
Collaborator

fangbinwei commented Nov 7, 2020

Sorry for the late reply. Your two projects are not equivalent, since you use @import in vue-app, but use import in vanilla-app.

If you do like below, they are equivalent. Then the build of vanilla-app will be failed like vue-app.

vanilla-app

main.js

import './index.scss';

index.scss

@import '~lib/index.scss';

It's the problem of @import, see here

@diachedelic
Copy link
Author

Ah ha! Straight from the horse's mouth, this is the correct way to import external styles into a Vue component:

<style lang="scss" src="lib/index.scss"></style>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants