Closed skolldev closed 6 years ago
First, you indeed do not need an extra loader, since storybook integrates with angular-cli.
File to import not found or unreadable: ~styles/helpers/variables.
means that the file you are importing can't be found. Try to add "styles" to the webpack's aliases in the .storybook/webpack.config.js
Thanks for your help igor! That did indeed solve it. I will leave this here in case somebody stumbles upon this:
const path = require('path');
module.exports = {
resolve: {
alias: {
styles: path.resolve(__dirname, '../src/styles')
}
}
};
@xDecus I am curious.
The solution you have given actually works if I import with ~.
However, when starting the app, @import '~...' doesn't work for me after I upgrade to angular 6.
Here is my repo: https://github.com/dereklin/nrwl-nx-workspace-demo/tree/integrate-storybook
Please note integrate-storybook is the branch.
In here i am trying @import '~...': https://github.com/dereklin/nrwl-nx-workspace-demo/blob/integrate-storybook/apps/app1/src/app/components/sparklines/sparklines.component.scss
When I start the app (npm run start:app1), I get:
ERROR in ./src/app/components/sparklines/sparklines.component.scss
Module build failed:
@import '~styles/variables';
^
File to import not found or unreadable: ~styles/variables.
in /Users/delin/sandbox/nrwl-nx-workspace-demo/apps/app1/src/app/components/sparklines/sparklines.component.scss (line 1, column 1)
Did you have to do anything special to make importing with ~ work in angular 6?
The other thing is:
styles: path.resolve(__dirname, '../src/styles')
is somewhat static, when I have multiple apps but only one webpack config, I need to dynamically point styles to different folders depending who which app the component belongs to, so this resolver need to evaluate the matching folder at run time or need to take the parent folder into consideration. Not sure how this can be achieved...
Hi @dereklin,
i just downloaded your project, yarn installed the dependencies and ran the storybook script. It started up flawlessly. Seems to be a faulty installation on your machine or something..
For your second question - your scss imports will mostly be helpers like placeholders, variables and mixins, right? Why do you need different folders for different components? If you do need that, just specify the full path of the import in your scss file and leave out the alias.
Cheers!
@xDecus Did you do git checkout integrate-storybook after you did git clone? I am getting this when I do npm run start:app1:
ERROR in ./src/app/components/sparklines/sparklines.component.scss
Module build failed:
@import '~styles/variables';
^
File to import not found or unreadable: ~styles/variables.
in C:\Users\Derek\sandbox\nrwl\nrwl-nx-workspace-demo\apps\app1\src\app\components\sparklines\sparklines.component.scss (line 1, column 1)
i 「wdm」: Failed to compile.
And you can read about the referenced issue with angular-cli as well.
Thanks.
I think you should add the styles
dir to the paths (not the includePaths
) to make them "aliased" for the angular cli.
Anyway, I will check the "stylePreprocessorOptions.includePaths" options from the #3824. (I assume this is something specific to the node-sass)
Got word from angular-cli team, fuzzy import like @import '~styles/variables' is not supported: https://github.com/angular/angular-cli/issues/11435#issuecomment-402230031
Has anyone figured out a solution to this yet? I am having a similar issue: command: ng test error:
ERROR in ./src/app/components/user-login/user-login.component.scss
Module build failed:
@import "functions";
^
File to import not found or unreadable: functions.
Try to define "functions" in the webpack's aliases (in .storybook/webpack.config.js ).
Can you show me an example of how I might do that? I have 3 webpack.config.js files First webpack.config.js:
var path = require("path")
module.exports = {
"entry": "./lib/index.js",
"output": {
"path": __dirname + "/build"
, "filename": "xxhash.js"
, "library": "XXH"
, "libraryTarget": "umd"
}
}
Second webpack.config.js file:
switch (process.env.NODE_ENV) {
case 'prod':
case 'production':
module.exports = require('./config/webpack.prod')({env: 'production'});
break;
case 'test':
case 'testing':
module.exports = require('./config/webpack.test')({env: 'test'});
break;
case 'package':
module.exports = require('./config/webpack.package')({env: 'package'});
break;
case 'dev':
case 'development':
default:
module.exports = require('./config/webpack.dev')({env: 'development'});
}
3rd webpack.config.js file:
module.exports = {
module: {
rules: [
{
test: /\.pug$/,
use: [
"pug-loader?self",
]
},
{
test: /\.css$/,
use: [
"style-loader",
"css-loader",
"sass-loader"
],
}
]
}
};
I am not sure what are those webpack.confg
s are, but @xDecus shared his soultion in this comment ☝️ . You should add the alias to the webpack.config.js in .storybook
dir.
I was having almost same trouble as you: every scss import that I have did not worked.
Here are a solution that solved my problem :
const path = require("path");
module.exports = {
module: {
rules: [
{
test: /\.scss$/,
loaders: ["sass-loader"],
include: path.resolve(__dirname, "../src/scss")
}
]
}
};
I have just only added the loader sass-loader
, just this one, no more.
Be aware of the include path that will no be the same and it will not be required in your case.
Below code works for me on Angular "@angular/core": "^11.0.3"
@import "/src/config"; // without tilde, it import _config.scss file placed under the src folder.
@import "~@logo-software/theme/base"; // tilde looks for node_modules folder
If you are reporting a bug or requesting support, start here:
Bug or support request summary
I'm using the default configs for everything - webpack and storybook config. The component i want to display in storybook has a *.component.scss file - when compiling i get the following error:
From what I've researched, this indicates multiple scss loaders - however, when i remove the webpack config test for scss, i get the following error instead:
Steps to reproduce
Please specify which version of Storybook and optionally any affected addons that you're running
Affected platforms
Screenshots / Screencast / Code Snippets (Optional)
Webpack.config.js
index.stories.ts