3

At the moment I'm working on a React and React Native app. They both use the same database so I decided to create another project just for that database so both projects can use the same files without me having to change it in 2 separate projects. I added that project as a package with npm i --save [link]. It works as expected. Can also use its exports inside the React app.

When starting the app I get this error:

ERROR in ./node_modules/common/database/index.ts 5:7

Module parse failed: Unexpected token (5:7)
File was processed with these loaders:
 * ./node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
| import logger from "../util/logger";
| 
> export enum DatabaseBackend {
|   Admin,
|   ReactNative,


ERROR in ./node_modules/common/repositories/booking.ts 5:57

Module parse failed: Unexpected token (5:57)
File was processed with these loaders:
 * ./node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
| import { Nanny, Parent } from "../types/user.type";
| 
> const toBookingList = bookings => bookings.map(([ b, id ]: [ DTOBooking, string ]) => toBooking(b, id));

I checked this post because he seems to have had a similar issue. So I changed my tsconfig.json from

"compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
// ...
}

to:

"compilerOptions": {
    "target": "ES6",
    "lib": ["DOM", "ES6", "DOM.Iterable", "ScriptHost", "ES2016.Array.Include"],
// ...
}

However the project still won't start. Should I compile the database project into JS instead of TS before using it? Any help would be appreciated.

Sylent
  • 474
  • 1
  • 9
  • 25
  • What do you have in the file "../util/logger" of your common module ? And TBH i dont think you should query the database from the client – Martin PELCAT Aug 08 '22 at 11:38
  • Oh I should have specified. The common is nothing other then types, methods and fetches from the firebase firestore. The "../util/logger" has 3 methods for warnings, logs and errors done with console.error etc... – Sylent Aug 08 '22 at 12:13
  • I have a same problem, @Sylent you have solved this problem ? – Jboucly Nov 25 '22 at 14:00
  • @Jboucly turned out someone else added react native packages into the common repository. Meaning for the web we couldn't use it. Apparently if I understood correctly at that time you will need something that will only load those packages for the right platform. What is your situation? – Sylent Nov 26 '22 at 21:52
  • @Sylent My situation is little different, i have front end in React and back in NestJS and i try use a SDK for use NestJS API in React, but when I try to use the SDK in the React app I have this error that comes – Jboucly Nov 28 '22 at 15:00

0 Answers0