Skip to content

Deep import from scoped npm package breaks webpack resolve.aliases #463

@gizm0bill

Description

@gizm0bill
➡ find . -type d \( -path ./build -o -path ./node_modules \) -prune -o -print
.
./package.json
./src
./src/app
./src/app/app.scss
./src/app/index.js
./src/styles
./src/styles/main.scss
./webpack.config.js
// webpack.config.js

var path = require('path');
module.exports =
{
  entry: path.resolve('src', 'app', 'index.js'),
  output: { path: path.resolve(__dirname, 'build'), filename: 'bundle.js' },
  module:
  {
    rules: [{ test: /\.scss$/, use: ['css-loader', 'sass-loader'] }]
  },
  resolve: 
  {
    // notice the "@"
    alias: { '@styles': path.resolve(__dirname, 'src', 'styles') }
  }
}
// src/app/index.js

require( './app.scss' );
// src/app/app.scss

@import '~@styles/main';
// src/styles/main.scss

$some-var: #fff;
body { background-color: $some-var; }
➡ webpack --config webpack.config.js
...
ERROR in ./src/app/app.scss
Module build failed:
@import '~@styles/main';
^
      File to import not found or unreadable: ~@styles/main.
Parent style sheet: stdin
      in /some/path/src/app/app.scss (line 1, column 1)
 @ ./src/app/index.js 1:0-23

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions