6

ERROR in ./app/index.scss Module not found: Error: Cannot resolve 'file' or 'directory' ./../node_modules css-loader/index.js in C:\Users\johnliang\Temp\webpack-angular/app @ ./app/index.scss 4:14-116 13:2-17:4 14:20-122

ERROR in ./app/index.scss Module not found: Error: Cannot resolve 'file' or 'directory' ./../node_modules style-loader/addStyles.js in C:\Users\johnliang\Temp\webpack-angular/app @ ./app/index.scss 7:13-68

index.scss is not loaded in the final webpack output.

3
  • 1
    Can you provide your Webpack configuration? What do your imports look like? Commented May 16, 2015 at 4:55
  • I have the same error, did you find the solution? Commented Jun 3, 2015 at 6:32
  • I found same issue. Check out here Commented Feb 1, 2017 at 1:57

2 Answers 2

22

Be sure you use

path.join(__dirname, 'src')

and not

__dirname + '/src'

in your webpack.config.js:

var path = require('path');

module.exports = {
  context: path.join(__dirname, 'src'),
...
Sign up to request clarification or add additional context in comments.

4 Comments

I had exactly the same issue, and this worked. im guessing it has to do with using the correct path separator for the OS
Not just for the context but resolve.root needs to have the proper slashes too.
@roman-d You sir just saved me like a day of debugging, thanks a lot!
i have having the same issue. Could you please let me know how to update the below code. const path = require("path"); const dist = path.resolve(__dirname, "dist"); const combineLoaders = require('webpack-combine-loaders'); module.exports = { entry: [ './src/index.js' ], output: { path: __dirname+'/public', publicPath: '/', filename: 'bundle.js' },
2

I had a similar issue to this whereby my webpack build was complaining about a .js file:

ERROR in ./node_modules/style-loader/lib/addStyles.js
Module not found: Error: Can't resolve './urls' in '/Users/<user>/path/to/project/node_modules/style-loader/lib'
 @ ./node_modules/style-loader/lib/addStyles.js 64:14-31

I must have copied this solution from a tutorial somewhere along the way (or many), but comparing to another project I have written, I realised that I had missed the extension '.js' to the resolve property in my webpack config:

resolve: {
  extensions: [
    '.scss',
    '.css',
    '.js' // <-- HERE
  ]
},

This fixed the issue for me, so definitely give this a go.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.