https://github.com/oscarmarina/import-typescritp-file-with-js-extension-fail
https://github.com/oscarmarina/import-typescritp-file-with-js-extension-fail
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/oscarmarina/import-typescritp-file-with-js-extension-fail
- Owner: oscarmarina
- License: mit
- Created: 2021-09-05T17:34:59.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-09-05T18:06:12.000Z (almost 4 years ago)
- Last Synced: 2025-02-08T09:13:04.632Z (4 months ago)
- Language: TypeScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Describe the bug [vitejs](https://vitejs.dev/)
Importing a typeScript file with .js extension from `html` file or a `typeScript` file fails with:
- [similar issue](https://github.com/vitejs/vite/issues/3040)
## Installation
```bash
npm i
```## Scripts package.json
```json
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"vite-build": "vite build",
"tsc-build": "tsc"
},
```### `index.html` root level just with the intention of redirecting to demo/index.html
```groovy
./
├── my-element-openwc-vitejs-ts/
│ ├── index.html
```
## master branch
### vite fail
```sh
npm run vite-build
``````sh
[vite] Internal server error: Failed to resolve import "../my-element-openwc-vitejs-ts.js" from "demo/index.html?html-proxy&index=0.js". Does the file exist?[plugin:vite:import-analysis]
``````groovy
./
├── my-element-openwc-vitejs-ts/
│ ├── demo/
│ │ └── index.html ====> try to import module my-element-openwc-vitejs-ts.js (fail)
│ ├── src/
│ │ └── MyElementOpenwcVitejsTs.ts
│ ├── .editorconfig
│ ├── .gitignore
│ ├── index.html
│ ├── LICENSE
│ ├── my-element-openwc-vitejs-ts.ts ====> try to import module MyElementOpenwcVitejsTs.js (fail)
│ ├── package.json
│ ├── README.md
│ ├── tsconfig.json
│ └── vite.config.js
```
## all-with-ts-extension branch
### vite OK
```sh
npm run vite-build
```### tsc fail
```sh
npm run tsc-build
``````sh
my-element-openwc-vitejs-ts.ts:1:41 - error TS2691: An import path cannot end with a '.ts' extension. Consider importing './src/MyElementOpenwcVitejsTs.js' instead.1 import { MyElementOpenwcVitejsTs } from './src/MyElementOpenwcVitejsTs.ts';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Found 1 error.
``````groovy
./
├── my-element-openwc-vitejs-ts/
│ ├── demo/
│ │ └── index.html ====> try to import module my-element-openwc-vitejs-ts.ts (OK)
│ ├── src/
│ │ └── MyElementOpenwcVitejsTs.ts
│ ├── .editorconfig
│ ├── .gitignore
│ ├── index.html
│ ├── LICENSE
│ ├── my-element-openwc-vitejs-ts.ts ====> try to import module MyElementOpenwcVitejsTs.ts (OK)
│ ├── package.json
│ ├── README.md
│ ├── tsconfig.json
│ └── vite.config.js
```