Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to run custom scripts inside react project #10151

Open
kdong007 opened this issue Nov 25, 2020 · 1 comment
Open

how to run custom scripts inside react project #10151

kdong007 opened this issue Nov 25, 2020 · 1 comment

Comments

@kdong007
Copy link

kdong007 commented Nov 25, 2020

Describe the bug

I have a project created using create-react-app xxx --template typescript.

I want to add some custom scripts to to miscellaneous things.

Here is my script in scripts/xxx.ts

import fs from "fs";
console.log("ttt", fs.readFile);

Steps to reproduce

  1. create-react-app xxx --template typescript
  2. add the script
  3. ts-node scripts/xxx.ts

Expected behavior

script runs successfully

Actual behavior

(node:50658) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/Users/kdong007/Desktop/projects/tapin-monorepo/test-react/scripts/tt.ts:1
import fs from "fs";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1053:16)
    at Module._compile (internal/modules/cjs/loader.js:1101:27)
    at Module.m._compile (/Users/kdong007/.config/yarn/global/node_modules/ts-node/src/index.ts:1043:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/kdong007/.config/yarn/global/node_modules/ts-node/src/index.ts:1046:12)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at main (/Users/kdong007/.config/yarn/global/node_modules/ts-node/src/bin.ts:225:14)
    at Object.<anonymous> (/Users/kdong007/.config/yarn/global/node_modules/ts-node/src/bin.ts:512:3)

Reproducible demo

(Paste the link to an example project and exact instructions to reproduce the issue.)

@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Dec 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant