denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
96k stars 5.31k forks source link

create-react-app does not run correctly #17669

Open ry opened 1 year ago

ry commented 1 year ago
# deno run -A npm:create-react-app cra-repo

Creating a new React app in /private/tmp/foobar/cra-repo.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...

added 1417 packages in 1m

231 packages are looking for funding
  run `npm fund` for details
error: Uncaught ReferenceError: require is not defined
        const init = require('react-scripts/scripts/init.js');
                     ^
    at file:///private/tmp/foobar/cra-repo/$deno$eval.js:2:22

Aborting installation.
  node  has failed.

Deleting generated file... node_modules
Deleting generated file... package.json
Done.

# ls cra-repo/
package-lock.json
Antonio476587 commented 1 year ago

I have executed the command without the --allow-all (-A) flag, and it stopped after I allowed it to use Deno.Command().spawn()

added 1416 packages in 2m

231 packages are looking for funding
  run `npm fund` for details
✅ Granted run access to "/home/theheredero/.deno/bin/deno".
error: Uncaught ReferenceError: require is not defined
        const init = require('react-scripts/scripts/init.js');
                     ^
    at file:///home/theheredero/cra-repo_3/$deno$eval.js:2:22

Aborting installation.
  node  has failed.

Deleting generated file... package.json
Deleting generated file... node_modules
Done.

Then I went to the create-react-app file, and the issue is created here in the executeNodeScript function. It is passing the string to the subprocess that is causing the error.

          `
        const init = require('${packageName}/scripts/init.js');
        init.apply(null, JSON.parse(process.argv[1]));
      `

Maybe we can apply the InternalTransformations to the subprocesses, I think it is better than replacing strings with regex.