2

Ive only been learning Javascript/Typescript since the start of the year as I decided to create a group of microservices that are all linked together. I have my own API created in nestJS and found that whenever I wanted to call the API from each microservice i was repeating the same code over and over again so I moved it all into its own separate package which I can use.

Every other project I have which uses my npm package does not cause any errors and works fine however these projects are done using babel. I decided to implement my new package into my react frontend project but whenever I import the package and try to use it I get an error

SyntaxError: D:\Projects\Node\Lab Maker\redditbot-frontend\node_modules\labmaker-api-wrapper\lib\utils\BaseAPI.js: Missing class properties transform.

I managed to fix this issue by installing the babel class transform package but then was presented with another error.

Failed to compile.

./node_modules/labmaker-api-wrapper/lib/utils/BaseAPI.js 13:9
Module parse failed: Unexpected token (13:9)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|
| class API {
>   APIBase;
|   APIUrl = 'http://localhost:3000';
|

I'm not sure what is wrong with my package or what causes this error but if anyone is able to take a look at the source code for my npm module and explain how I would fix this issue that would be helpful. https://github.com/LabMaker/API-Wrapper

this is the npm package https://www.npmjs.com/package/labmaker-api-wrapper

Cartion
  • 149
  • 3
  • 12
  • It doesn't look like the question is about making an NPM package, but rather how to build this code within your React project, right? – Emile Bergeron Aug 17 '21 at 15:19
  • I think its both im not fully sure as the error i am getting is only to do with my NPM package which makes me think i did something wrong when coding/publishing it as its my first time publishing my own package. I will update the question to make it clear. – Cartion Aug 17 '21 at 15:36
  • For the NPM package part, you might want to look at: [How to publish a module written in ES6 to NPM?](https://stackoverflow.com/q/29738381/1218980) – Emile Bergeron Aug 17 '21 at 15:40
  • Or: [Writing npm modules in TypeScript](https://stackoverflow.com/q/30928253/1218980) – Emile Bergeron Aug 17 '21 at 15:44
  • I have gone over each link you sent and have tried using each response but I still end up with the same problem I think my issue is with babel instead of my node package then. – Cartion Aug 17 '21 at 17:01

0 Answers0