简体   繁体   English

Javascript 文件导致 React (Typescript) 无法启动

[英]Javascript file cause React (Typescript) fail to start

I have a React project with Typescript.我有一个带有 Typescript 的 React 项目。 One day I create a javascript file in src/ and then my React app failed to start on localhost.有一天,我在src/中创建了一个 javascript 文件,然后我的 React 应用程序无法在 localhost 上启动。 Any explanation about this would be appriciated.对此的任何解释都将得到应用。
Evironment : Node 16.13.1环境:节点16.13.1
Step to reproduce :重现步骤

git clone git@github.com:manaclan/fun-pms-frontend.git
cd fun-pms-frontend
git checkout vinhngo

Inside package.json remove:内部 package.json 移除:

"@types/react-facebook-login": "^4.1.4"
"react-facebook-login": "^4.1.1"

Then npm install and npm start will notify that localhost:3000 failed to connect.然后npm installnpm start会通知 localhost:3000 连接失败。 Removing src/setupProxy.js will make the server start as normal删除src/setupProxy.js将使服务器正常启动

That's because JavaScript is not allowed in Typescript projects, you would need to modify your Typescript config, add the following flag to to the config file那是因为 JavaScript 在 Typescript 项目中是不允许的,你需要修改你的 Typescript 配置,将以下标志添加到配置文件

--allowJs --allowJs

Depending on the module bundler you probably also have to set the output directory for the transpiled Typescript files.根据模块捆绑器,您可能还必须为转译的 Typescript 文件设置 output 目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM