How to compile typescript? - javascript

If I use tsc it doesn't work. If I don't have tsc but have typescript, it still doesn't work. What can I do?

You have to install the typescript library like this.
npm install typescript --save-dev
Then npx tsc command will work.
What you have installed is a deprecated library called tsc
Check here. So you may have to remove that first with the following command
npm uninstall tsc

Related

Unable to use typescript with expo - "It looks like you're trying to use TypeScript but don't have the required dependencies installed"

I am receiving an error while trying to use Typescript with my existing expo project.
While following the docs, I created a tsconfig.json file in the project root.
When running expo start, I am prompted to install the typescript dependencies. However, after these are successfully installed (tick message appears in console: √ Installed typescript#~4.3.5, #types/react#~17.0.21, #types/react-native#~0.67.6), I receive the following error:
It looks like you're trying to use TypeScript but don't have the required dependencies installed.
Please install #types/react by running:
yarn add --dev #types/react#~17.0.21
If you're not using TypeScript, please remove the TypeScript files from your project and delete the tsconfig.json.
error Command failed with exit code 1.
After following the instructions and running the yarn add .... command, I keep seeing the same error message.
I have tried deleting the node_modules folder and package-lock.json file to no avail. I have also tried following this answer.
Any assistance would be appreciated, thank you.
Seems to be a bug. It works if I install #types/react on the specific version that Expo requests (17.0.21).
yarn add --dev #types/react#17.0.21
Just re-install expo-cli npm install -g expo-cli.
I don't know which of the following worked, but I ran the following commands and the problem went away.
sudo npm install -g expo-cli
sudo npm install -g #types/react
sudo npm install -g #types/react-native
sudo npm install -g typescript
yarn add expo-cli
solved for me.
I had the same issue. I resolved it by :
1- delete the node_modules.
2- update expo to the latest version using npm i -g expo-cli
hope this will help someone
if you installed #types/react remove that from your dev dependencies

win10 yarn cant find typescript

I have a git repo that I'm supposed to launch with the command react-scripts start. When I run this command I get this response saying typescript cant be found:
react-scripts start
It looks like you're trying to use TypeScript but do not have typescript installed.
Please install typescript by running npm install typescript.
If you are not trying to use TypeScript, please remove the tsconfig.json file from your package root (and any TypeScript files).
I have tried installing typescript in command prompt with npm i typescript, npm i -g typescript, yarn add typescript, yarn global add typescript, and "choco install typescript".
I am able to run typescript files, but still if I try to launch my program I get that error saying I dont have typescript installed.
If I just run tsc in my command prompt or powershell I get some error alerts that I have tried to solve but no luck yet:
tsc
src/App.tsx:12:5 - error TS2307: Cannot find module 'react/jsx-runtime' or its corresponding type declarations.
12 <UserAccountContext.Provider value={guestAccount}>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13 <div className="App container">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
24 </div>
~~~~~~~~~~~~
25 </UserAccountContext.Provider>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/App.tsx:13:7 - error TS2339: Property 'div' does not exist on type 'JSX.IntrinsicElements'.
13 <div className="App container">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/App.tsx:15:9 - error TS2339: Property 'div' does not exist on type 'JSX.IntrinsicElements'.
Is there some way I can ensure typescript is installed? Ive tried running the installation commands in both powershell and command prompt.
You can just simply install in your project by using yarn add typescript #types/node #types/react #types/react-dom #types/jest or npm install --save typescript #types/node #types/react #types/react-dom #types/jest.
If you have a problem with the scripts perhaps updating them will solve it, you can try this command: npm install react-scripts#latest
For further information you can check this links: Create React App and Typescript Docs
Also you may check frameworks that have native support to TS, like Next and Gatsby

Error installing dependencies with ESLint, the STDIN does not get the key

Hello I am configuring with ESLint for do this i do the following steps
npm install eslint --save-dev
npx eslint --init
But when the wizard ask about
Which style guide do you want to follow?
and select google or airbnb
this ask another question
Checking peerDependencies of eslint-config-airbnb-base#latest The
config that you've selected requires the following dependencies:
eslint-config-airbnb-base#latest eslint#^4.19.1 || ^5.3.0
eslint-plugin-import#^2.14.0 ? Would you like to install them now with
npm? (Y/n)
but the STDIN doesn't work, then I cannot continue with the configuration.
I tried to install the dependencies separately but it did not work
Any idea?
Thanks
Solved installing npm install inquirer#6.3 --save-dev first, this is a issue in: https://github.com/eslint/eslint/issues/11862

bash: tslint: command not found

I tried use tslint --fix but get bash: tslint: command not found....
I installed tslint using command: yarn global add tslint typescript.
My machine use Centos 7.
I've run into the same problem recently. Yarn output says it added "tslint" binary, but it's lying. To actually install it you need to run Yarn as root, so:
sudo yarn global add tslint typescript
I needed to delete the /node_modules folder and run npm install and it was fixed again

Transpile with babel CLI

I want to transpile several js files that are in ES6 to be compatible with chrome, but it seems the docs in http://babeljs.io/docs/usage/cli/ are not accurate.
After doing the first few steps I type in the console: babel and get:
You have mistakenly installed the babel package, which is a no-op in
Babel 6. Babel's CLI commands have been moved from the babel package
to the babel-cli package.
npm uninstall babel
npm install --save-dev babel-cli
See http://babeljs.io/docs/usage/cli/ for setup instructions.
And even if I run those two commands it mention, I still get the same error.
So my question is how are you supposed to transpile files with Babel and CLI?
A bit old question, but in case someone ended here through Google like me:
I had the same problem, just ran
npm install --save-dev babel-cli
in a new and completely empty directory in order to test something and could not transpile when calling babel through npx with the same error. I didn't have Babel installed globally, but after a while I noticed npm didn't create the package.json file. So I deleted everything, created empty package.json with just
{
}
installed babel-cli again (npm now added dev dependency to the json file) and now it works fine.

Categories