-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Subtle error when importing typescript definition file into vue file #2132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I got the same error when I config typescript with ESLint (airbnb). It seems to work fine when you just use tslint as usual. |
Just ran into this issue, super frustrating since it leaves zero trace back to what the issue could be. EDIT: Ran into this issue because the module I was using did not automatically build. |
I have run into a similar issue, and I think the problem can be traced back to a known bug from What seems to be causing that error is using the A temporal solution is to disable it using the following module.exports = {
chainWebpack: config => {
config.module
.rule('ts')
.use('ts-loader')
.loader('ts-loader')
.tap(options => {
options.transpileOnly = false;
return options;
});
},
}; |
After further investigation my issue was caused because one of my node modules did not transpile TS, so the main file did not exist. No error hinted to that, so sounds like the issue might be bigger than that. |
The approach I indicated above only works for development, to fix it in both production and development use: module.exports = {
chainWebpack: config => {
const rule = config.module.rule('ts');
rule.uses.delete('thread-loader');
rule.use('ts-loader')
.loader('ts-loader')
.tap(options => {
options.transpileOnly = false;
options.happyPackMode = false;
return options;
});
},
}; @OzairP What do you mean that one of your modules doesn't transpile TS, isn't webpack doing the transpilation? In any case, a new app created with the CLI will suffer this problem, so this fixes it for the time being. |
I had imported a module via git not npm and npm had not run the build phase so there was no transpiled code. My point is our cause of the issue is vastly different, there is no debuggable error messages either. |
I just started seeing this error today. I'm calling |
@mmmeff unfortunetly this is not debuggable. There are numerous reasons it can be happening. I would check your import transformation settings because TS did introduce "esModuleInterop" in tsconfig. |
I have run into the same problem. Let me add what I found: Problem appears only if you have some I run several tests for simple TS code with babel@7 transpilation without webpack. And I think I found a reason of the issue.
Now it is obvious that JS expects Well, the core issue is not |
You can't export any actual JavaScript code from declaration files ( More info here: https://lukasbehal.com/2017-05-22-enums-in-declaration-files/ |
I'm encountering this with a codemirror embed in my app. Is there are proper solution at this point? |
Encountering this issue when adding an enum to my TypeScript definition files in a Vue CLI project. |
@ericdfields I've ended up with using string unions instead of enums. type Direction = 'up' | 'down' | 'left' | 'right'
///
function move(d: Direction) { /* some code */ }
///
move('up')
move('left')
move('dawn') For me, code looks cleaner. And TS still gets your back with |
Great points! Declaring enum as @KubaJastrz show produces code, while the Direction type (@zaverden) becomes a type that typescript handles. Illustrates what can be an issue, I guess. |
I've seen this a few times. I think the right solution (given recent enough typescript, I'm using 4.1.3) is |
As @garyo mentioned, the more elegant way nowadays is using typescript {
externals: [
(ctx, callback) => {
/** in order to exclude remaining type imports from final bundles */
if (/(\.types)$/.test(ctx.request)) {
return callback(null, '({})', 'root');
}
callback();
},
]
} |
Facing same with Vue 2.6.12 😢 |
这个错误我今天也遇到了,不过我不是定义枚举类型,而是直接报 shims-tsx.d.ts 和 shims-vue.d.ts 文件无法编译
shims-tsx.d.ts : import Vue, { VNode } from 'vue'
declare global {
namespace JSX {
interface Element extends VNode {}
interface ElementClass extends Vue {}
interface IntrinsicElements {
[elem: string]: any
}
}
} |
Version
3.0.0-rc.12
Node and OS info
Node v10.8.0 / Npm 6.3.0 / Linux WS-001 4.17.13-arch1
Steps to reproduce
src
folder (a simple typescript declaration file, namedMyEnums.d.ts
):main.ts
insrc
:npm run serve
, and you get the error:MyEnums.d.ts
toMyEnums.ts
npm run serve
, and everything is fine.MyEnums.ts
toMyEnums.d.ts
No type errors found
, when you browse to the addresshttp://localhost:8081
, you get the report:URIError: Failed to decode param '/%3C%=%20BASE_URL%20%%3Efavicon.ico' ...
, and a blank web page.What is expected?
No error when using typescript definition files with solution
What is actually happening?
The build tools are complaining about missing dependency, or when using more specific path (so that I make sure the path ends in .ts) I get 'Output generation failed'.
I run into the issue when building my solution, and after pinning it down to my enums, I realized it has something to do with the naming of the definition files ending in .d.ts and not in .ts.
The text was updated successfully, but these errors were encountered: