1

I have the following basic configuration in my webpack which is relevant to loading my styles via TypeScript:

{
  module: {
    rules: [{
      test: /\.s?css$/,
      use: [
        { loader: 'style-loader' },
        {
          loader: 'typings-for-css-modules-loader',
          options: {
            sass: true,
            modules: true,
            camelCase: true,
            importLoaders: 1,
            namedExport: true,
            localIdentName: '[name]__[local]__[hash:base64:5]',
          }
        },
        { loader: 'sass-loader' },
      ]
    }],
  },
  resolve: {
    alias: {
      app: srcPath,
    },
    modules: ['node_modules', srcPath],
    extensions: ['.js', '.jsx', '.json', '.scss', '.css', '.tsx', '.ts', '.d.ts'],
  },
}

In my tsconfig.json, I have the following to match:

{
  "compilerOptions": {
    "paths": {
      "app": ["./app"]
    }
  }
}

However, I am consistently getting an error when trying to load a file from app/styles/root.scss, with the following project structure:

├── components
│   └── Root.tsx
├── styles
│   └── root.scss
├── index.hbs
├── index.scss
├── index.scss.d.ts
└── index.tsx

enter image description here

It seems like TypeScript is not able to resolve this path correctly. If this were a plain JS based file, it would work fine.

Strangely, I can add a root.scss.d.ts with the defintions for the CSS file and it will resolve correctly. I think this is a bit strange because I am specifically using typings-for-css-modules-loader for this task.

How do I get TypeScript to resolve these scss files under the styles directory?

1
  • try '../styles/root.scss' Commented Jul 19, 2017 at 14:01

1 Answer 1

1

Fix

Simply

declare module "*.scss";

More

See the JavaScript to TypeScript migration guide : https://basarat.gitbooks.io/typescript/content/docs/types/migrating.html

Sign up to request clarification or add additional context in comments.

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.