[英]typescript import doesn't work
I'm trying to solve this problem is already more than 6-8 hours. 我正在尝试解决此问题已经超过6-8个小时。 I think one of the problems is my english.
我认为问题之一是我的英语。 =)
=)
I use atom editor, electron, typescript, react 我使用原子编辑器,电子,打字稿,反应
tsconfig.json tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"isolatedModules": false,
"jsx": "react",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": false,
"noImplicitAny": false,
"noImplicitUseStrict": false,
"removeComments": true,
"noLib": false,
"preserveConstEnums": true,
"suppressImplicitAnyIndexErrors": true
},
"exclude": [
"node_modules",
"typings/browser",
"typings/browser.d.ts"
],
"compileOnSave": true,
"buildOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
app.ts: 应用程式:
import {hello} from "./func";
hello("TypeScript");
func.ts 功能
export function hello(name: string){
console.log(`Hello, ${name}`);
}
Start electron and get error: 启动电子并得到错误:
Uncaught SyntaxError: Unexpected token import
then, create file react-test.ts: 然后,创建文件react-test.ts:
import * as React from "react";
get error in atom editor: 在原子编辑器中出现错误:
Cannot find module 'react'
Question: I do not want more theory. 问题:我不希望有更多理论。 There is a specific example.
有一个具体的例子。 Please help me to solve it.
请帮我解决。 By the way I did not have any problem with babel =)
顺便说一句,我对babel =没有任何问题
Update #1: 更新#1:
Electron run command: 电子运行命令:
npm start
First you need to transpile TypeScript to JavaScript with tsc
command and in index.html
file require app.js
instead app.ts
. 首先,您需要使用
tsc
命令将TypeScript转换为JavaScript,并且在index.html
文件中需要使用app.js
而不是app.ts
Then run Electron with npm start
然后以
npm start
运行Electron
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.