3

When using Create React App and TypeScript, a file is auto-generated in the src directory: react-app-env.d.ts. This file seems necessary to support image imports as discussed here: https://github.com/facebook/create-react-app/issues/6560.

When using Format.JS, I extract messages using the following command:

yarn extract 'src/**/*.ts*' --out-file lang/en-GB.json --id-interpolation-pattern '[sha512:contenthash:base64:6]'

But unfortunately this results in this error:

warning Error: Error processing file src/react-app-env.d.ts
Debug Failure. Output generation failed
Done in 9.64s.

I need to process both .ts and .tsx files. I have tried to hack the search pattern to exclude the specific file name, but I am now completely stumped as I am unsure of its precise specification.

As a workaround I can delete the file prior to extraction, but this is very annoying!

PJRobot
  • 1,306
  • 13
  • 14

2 Answers2

11

Just use 'src/**/!(*.d).ts*' pattern in your extract script, this will exclude all .d.* files from your src folder.

PJRobot
  • 1,306
  • 13
  • 14
celiulitas
  • 206
  • 5
  • 11
  • Many thanks, just helped me sort a very annoying issue. I only got it to work by changing your `{ts,tsx}` for `ts*` so have edited you answer accordingly. – PJRobot Sep 13 '21 at 09:43
2

You can also do formatjs extract --ignore='**/*.d.ts'.

This is a good search https://github.com/search?l=JSON&q=%22formatjs+extract%22&type=Code if you're curious about usages.

I threw in a PR to update the documentation.

Josh Unger
  • 6,717
  • 6
  • 33
  • 55