Open leesiongchan opened 7 years ago
According to this that error happens when you try to import "foo.d.ts";
rather than import "foo.ts";
, but you haven't provided enough information to see if that's whats wrong here.
This loader will produce .d.ts
typings file to allow typescript to use import
instead of require
.
The at-loader allows Webpack to know how to deal with .ts
files and the TypeScript compiler. Webpack handles a lot of it's dependancy management via import statements, and it uses these loaders to support various formats, like TypeScript, LESS, and SASS.
The TypeScript compiler can output a .d.ts
file alongside the .js
output, but that is generally not needed in your own application as you have the source .ts
files available, and the TypeScript compiler is fine about getting the type information from those. The generated .d.ts
file is mainly for distributing alongside a compiled .js
output e.g. if you're making a library to publish, rather than an application to run.
It's the TypeScript compiler that allows the use of import
instead of require
, as it transpiles the code to whatever version of EMCAScript you're targeting.
TypeScript will look for .d.ts
files when you use import.
e.g. import "lodash";
might look for "Typings\lodash.d.ts" and "node_modules\@types\lodash\index.d.ts".
The error message you have explicitly says "TypeScript declaration files should never be required", which to me means that somewhere there is import "[X].d.ts";
and it doesn't like it.
You can see that this error is generated at this location in the at-loader
source: https://github.com/s-panferov/awesome-typescript-loader/blob/master/src/index.ts#L54
And that it's testing the filename to see if it matches the pattern .d.ts
: https://github.com/s-panferov/awesome-typescript-loader/blob/master/src/index.ts#L35
WARNING in ./src/components/.../styles.css.d.ts
(Emitted value instead of an instance of Error) [at-loader] TypeScript declaration files should never be required
NonErrorEmittedError: (Emitted value instead of an instance of Error) [at-loader] TypeScript declaration files should never be required
not reproducible for me. @leesiongchan could you provide demo repo for your issue?
I an also facing the same issue as @leesiongchan
@besrabasant Do you have an example that reproduces the problem?
No, I do not have but I can provide you with one. @AndyCJ
Here's the example-repo.
Your webpack config is defined to load up modules trying these extensions in order: extensions: ['*', '.js', '.jsx', '.vue', '.ts', '.tsx', '.css','.scssm']. https://github.com/besrabasant/awesome-typescript-bug/blob/atl-bug/webpack.mix.js#L77
So when you do "import * as styles from "./styles.scssm";" in ErrorComponent.tsx, https://github.com/besrabasant/awesome-typescript-bug/blob/atl-bug/reactjs/core/components/ErrorComponent.tsx#L2
it tries to load up "styles.scssm.d.ts". https://github.com/besrabasant/awesome-typescript-bug/blob/atl-bug/reactjs/core/components/styles.scssm.d.ts
As posted above, don't try to import "*.d.ts" files: https://github.com/Jimdo/typings-for-css-modules-loader/issues/50#issuecomment-344539290
Deleting "styles.scssm.d.ts" gets rid of the error, but then you get another error about "styles.scssm" not being found.
The problem described by this thread is solved though.
Deleting "styles.scssm.d.ts" gets rid of the error, but then you get another error about "styles.scssm" not being found.
Yeah, I know that @AndyCJ. But is there any other way to get rid of the "latter" error?