nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.59k stars 2.36k forks source link

Error running tests for Express app when library imports from 3rd party #21694

Open richmondp opened 9 months ago

richmondp commented 9 months ago

Current Behavior

I have configured a very simple monorepo with an express app and 2 JS libraries (using the 3 commands below).

The first library has a function that takes a string and converts it to lowercase using javascript's toLowerCase() function.

The second library also converts to lowercase but the library function imports the lowerCase function from lodash.

A basic test is setup in the express app for both library functions, without-import.test.ts (native JS function) and with-import.test.ts (lodash).

The without-import.test.ts runs without any problems, but the with-import.test.ts fails with the error `SyntaxError: Unexpected token 'export'

Commands to re-create the repo npx create-nx-workspace --preset=express npx nx g @nx/js:lib libs/lowercase npx nx g @nx/js:lib libs/lowercase-import

Expected Behavior

I would expect that I could run tests that call a library that with it's own imports.

When running nx run sample-api:test, all tests should pass

GitHub Repo

https://github.com/richmondp/nx-express-app-test-failures

Steps to Reproduce

  1. Run nx run sample-api:test. 1 test will pass, 1 test will fail.

Nx Report

Node   : 18.18.0
   OS     : darwin-arm64
   npm    : 9.8.1

   nx (global)        : 18.0.2
   nx                 : 18.0.2
   @nx/js             : 18.0.2
   @nx/jest           : 18.0.2
   @nx/linter         : 18.0.2
   @nx/eslint         : 18.0.2
   @nx/workspace      : 18.0.2
   @nx/devkit         : 18.0.2
   @nx/eslint-plugin  : 18.0.2
   @nx/express        : 18.0.2
   @nx/node           : 18.0.2
   @nrwl/tao          : 18.0.2
   @nx/vite           : 18.0.2
   @nx/web            : 18.0.2
   @nx/webpack        : 18.0.2
   typescript         : 5.3.3

Failure Logs

No response

Package Manager Version

No response

Operating System

Additional Information

No response

github-actions[bot] commented 9 hours ago

This issue has been automatically marked as stale because it hasn't had any activity for 6 months. Many things may have changed within this time. The issue may have already been fixed or it may not be relevant anymore. If at this point, this is still an issue, please respond with updated information. It will be closed in 21 days if no further activity occurs. Thanks for being a part of the Nx community! 🙏