How to setup a nx workspace for plain javascript (Cannot find module 'typescript')?

965 views Asked by At

I want to create a nx workspace for plain react apps.

Create Workspace

npx create-nx-workspace@latest # installs 15.2.1
# style: package-based
# distributed caching: NO

Install react-package

npm install -D @nrwl/react

Create js react app

npx nx g @nrwl/react:app my-new-app --js

But if I try to start the app

npx nx serve my-new-app

I get following error:

enter image description here

Why is the module typescript needed in a plain js app? Or why is it not installed when it is needed?

Thanks

1

There are 1 answers

0
jamiebarrow On

I've had this as well with @nrwl/js in a package based monorepo setup using create-nx-workspace, where I tried to run @nrwl/js:init but it seems to do nothing, and then @nrwl/js:lib gives me the error Cannot find tsconfig.base.json.

If I instead use create-nx-workspace to choose an integrated monorepo setup, and choose to use the ts option for an empty monorepo with the JS/TS plugin preinstalled, then it is setup correctly.

Perhaps generating the repo with the integrated react setup can help you pin down what's missing for your package based setup.

Apart from that, perhaps you could check the Nx Github to see if there's any issue relevant, e.g. the one below:

To me it seems like a bug, or at least, if its not being used in the intended way, its a user experience issue that may they need to improve - perhaps its documented on the website, but for beginners, just using create-nx-workspace should be the easiest way to get started.

Update: I see that the Package-Based Repo Tutorial actually does mention to install TypeScript manually, but my point above still remains - create-nx-workspace should do the work I need to create a workspace, TypeScript seems required for most if not all workspaces, so having it as a manual step seems to defeat the point.