cli icon indicating copy to clipboard operation
cli copied to clipboard

Support for javascript template when initialize latest React Native

Open flixyudh opened this issue 1 year ago • 3 comments

Describe the Feature

React Native use typescript by default starting from v0.71, but I'm not familiar with typescript so I keep use javascript instead. even tough typescript not blocking me to use javascript but I'm concern about typescript related packages that already packed.

Last time, I've tried to remove any typescript related packages base on Adding TypeScript to an Existing Project documentation but things get complicated to setup babel and jest that already use typescript.

I've tried to search how to initialize React Native with javascript but I'm not found it yet, also there's so many post about how to use javascript instead of typescript in React Native

So Is it possible to support javascript template while keeping typescript as default when initialize React Native?

Possible Implementations

I think about add --use-js or --javascript argument when initialize React Native, something like this:

# init React Native with typescript
npx react-native@latest init MyApp 

# init React Native with javascript
npx react-native@latest init MyApp --use-js # or --javascript

Related Issues

Several links that can be used for consideration to support javascript :

  1. I want to init my project using pure js template
  2. React Native Init Command Generating Typescript Project
  3. why react native project is creating in typescript ?
  4. Whenever I try to create New React Native APP using npx react-native init APP_NAME command it creates typescript instead of javascript project

flixyudh avatar Feb 09 '24 14:02 flixyudh

good idea for bootstrapping our small project

ajitaro avatar Mar 01 '24 06:03 ajitaro

There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

github-actions[bot] avatar May 31 '24 03:05 github-actions[bot]

This would be nice to see as I don't use TypeScript and just ran into this.

Robdel12 avatar Jun 01 '24 06:06 Robdel12

Hey! We decided to move Community Template to TypeScript and that's the one that'll support and upgrade. If you want to use custom template you can always leverage --template option for init command, read more here.

szymonrybczak avatar Aug 28 '24 15:08 szymonrybczak

@szymonrybczak could you enlighten me where do i get the latest javascript example project? I want to try to mix the latest javascript project template created by init with the latest react native version before I move to --template command 😆

flixyudh avatar Sep 12 '24 11:09 flixyudh

@flixyudh As of my knowledge there's only one maintained by Community and it's living under this repository: https://github.com/react-native-community/template, if you want to specifically use JavaScript in your template you need to migrate it on your own.

szymonrybczak avatar Sep 13 '24 11:09 szymonrybczak

Hi @szymonrybczak could you guide me, why when I tried

npx react-native@latest init TestingTemplate --template react-native-javascript-template

I got an error:

⚠️ The `init` command is deprecated.
The behavior will be changed on 12/31/2024 (107 days).

- Switch to npx @react-native-community/cli init for the identical behavior.
- Refer to the documentation for information about alternative tools: https://reactnative.dev/docs/getting-started

Running: npx @react-native-community/cli init

                                                          
               ######                ######               
             ###     ####        ####     ###             
            ##          ###    ###          ##            
            ##             ####             ##            
            ##             ####             ##            
            ##           ##    ##           ##            
            ##         ###      ###         ##            
             ##  ########################  ##             
          ######    ###            ###    ######          
      ###     ##    ##              ##    ##     ###      
   ###         ## ###      ####      ### ##         ###   
  ##           ####      ########      ####           ##  
 ##             ###     ##########     ###             ## 
  ##           ####      ########      ####           ##  
   ###         ## ###      ####      ### ##         ###   
      ###     ##    ##              ##    ##     ###      
          ######    ###            ###    ######          
             ##  ########################  ##             
            ##         ###      ###         ##            
            ##           ##    ##           ##            
            ##             ####             ##            
            ##             ####             ##            
            ##          ###    ###          ##            
             ###     ####        ####     ###             
               ######                ######               
                                                          

              Welcome to React Native 0.75.3!                
                 Learn once, write anywhere               

✔ Downloading template
✔ Copying template
✔ Processing template
ℹ Executing post init script 
✖ Processing template
error Installing pods failed. This doesn't affect project initialization and you can safely proceed. 
However, you will need to install pods manually when running iOS, follow additional steps in "Run instructions for iOS" section.

but when I run cd TestingTemplate && yarn && RCT_NEW_ARCH_ENABLED=1 bundle exec pod install --project-directory=./ios there's no error appear.

is there someway I can run seamlessly like rnc/cli do when running init?

https://github.com/flixyudh/react-native-javascript-template

flixyudh avatar Sep 15 '24 06:09 flixyudh

ups, it's because I specify postInitScript in template.config.js, when I comment postInitScript, the template run seamlessly like what rnc/cli do.

~but I don't know why if I specify postInitScript, the script raise an error even when I add script from the doc~

Edited

triggering error when run script.js

Error: Command failed with EACCES: {tempFolder}/node_modules/react-native-javascript-template/script.js

script.js

#!/usr/bin/env node
const ora = require('ora');

const spinner = ora('Executing post init script ');

new Promise((resolve) => {
  spinner.start();
  console.log('Wakwaw')
  resolve();
}).then(() => {
  spinner.succeed();
}).catch(() => {
  spinner.fail();
  throw new Error('Something went wrong during the post init script execution');
});

flixyudh avatar Sep 15 '24 07:09 flixyudh

@flixyudh the Pods error that you hit is not necessarily related to Pods, there was a regression that most of errors from init command were catched with this error (will be fixed in next version). For more reliable informations for now you can use --verbose option. In case of your script try running your script in separate environment node script.js, this error seems to me maybe ora is not installed or not available.

szymonrybczak avatar Sep 16 '24 04:09 szymonrybczak