Subtle error when importing typescript definition file into vue file
See original GitHub issueVersion
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
- vue create test
- Add the following to
src
folder (a simple typescript declaration file, namedMyEnums.d.ts
):
export const enum MyEnums {
C0 = 'ABC',
C1 = 'DEF'
}
- Add the following to
main.ts
insrc
:
import { MyEnums } from '@/MyEnums';
interface MyIf {
enums: MyEnums,
name: string,
}
let p0: MyIf = {
enums: MyEnums.C0,
name: 'My name',
}
- Run
npm run serve
, and you get the error:
This dependency was not found:
* @/MyEnums in ./src/main.ts
- Rename
MyEnums.d.ts
toMyEnums.ts
- Run
npm run serve
, and everything is fine. - Rename
MyEnums.ts
toMyEnums.d.ts
- Change the code above to:
import { MyEnums } from '@/MyEnums.d';
interface MyIf {
enums: MyEnums,
name: string,
}
let p0: MyIf = {
enums: MyEnums.C0,
name: 'My name',
}
- Run ‘npm run serve’, and you get the error:
Using 1 worker with 2048MB memory limit
94% after seal
ERROR Failed to compile with 1 errors 5:46:44 PM
error in ./src/MyEnums.d.ts
Module build failed (from ./node_modules/ts-loader/index.js):
Error: Debug Failure. Output generation failed
at Object.transpileModule (/home/user/temp/ts/test/node_modules/typescript/lib/typescript.js:100526:29)
at getTranspilationEmit (/home/user/temp/ts/test/node_modules/ts-loader/dist/index.js:231:74)
at successLoader (/home/user/temp/ts/test/node_modules/ts-loader/dist/index.js:33:11)
at Object.loader (/home/user/temp/ts/test/node_modules/ts-loader/dist/index.js:21:12)
@ ./src/main.ts 10:0-38 12:9-16
@ multi (webpack)-dev-server/client?http://192.168.1.48:8081/sockjs-node (webpack)/hot/dev-server.js ./src/main.ts
Type checking in progress...
No type errors found
Version: typescript 3.0.1
Time: 1984ms
- Even though you get
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.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:14
- Comments:18 (2 by maintainers)
Top Results From Across the Web
VSCode showing "cannot find module" TS error for .vue import ...
Solution 1 (temporary hack) ... Start VS Code from inside the Vue project's root folder. (The same folder as the correct tsconfig.json .)...
Read more >GoJS with ES6 Modules -- Northwoods Software
Note that all those modules the depend on GoJS must import exactly the same library file, in this case "../release/go-module.js". Any inconsistencies will...
Read more >Documentation - TypeScript 4.3
In JavaScript, it's pretty common for APIs to convert values that are ... Try it out with imports to CSS, SVGs, PNGs, font...
Read more >import module error with Vue 2.0 and typescript
Error comes from typescript language service, not from the IDE; Typescript compiler/service doesn't currently handle .vue files (https://github.
Read more >rollup.js
You can provide an optional Rollup configuration file to simplify command line ... reference for the module behaviors defined in the ES2015 specification, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have run into the same problem. Let me add what I found:
Problem appears only if you have some
enum
s in your.d.ts
file. It happens becauseenum
is not only a type information that can be stripped, but it has some run-time information (I mean enum values).I run several tests for simple TS code with babel@7 transpilation without webpack. And I think I found a reason of the issue.
enums.d.ts
intoenums.d.js
import { SomeEnum } from './enums'; const value: SomeEnum = 2;
) then transpiled JS does not have a reference to enum, because babel just strip it. And this case causes no errorsNow it is obvious that JS expects
enums.js
file, but we have onlyenums.d.js
. And here it fails.Well, the core issue is not
vue-cli
, but I’m not sure where we should report itThe approach I indicated above only works for development, to fix it in both production and development use:
@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.