nx icon indicating copy to clipboard operation
nx copied to clipboard

`@nrwl/webpack` breaks jest by exporting `.d.ts` files from `index.js`

Open hiddenist opened this issue 2 years ago • 0 comments

Current Behavior

Tests utilizing the @nrwl/webpack package fail because the index.js file in the built code is attempting to export two schema.d.ts files. I'm getting this in my unit tests for my own generators that extend the react and expo generators.

I was able to address this in my original repo by applying this patch:

diff --git a/index.js b/index.js
index 222c2849d7855ee4a8ff0f23525ddc7957f10b17..8d019a925e3b1b7ed24634c0be5008b797595455 100644
--- a/index.js
+++ b/index.js
@@ -6,6 +6,4 @@ tslib_1.__exportStar(require("./src/generators/webpack-project/webpack-project")
-tslib_1.__exportStar(require("./src/executors/dev-server/schema"), exports);
 tslib_1.__exportStar(require("./src/executors/dev-server/dev-server.impl"), exports);
 tslib_1.__exportStar(require("./src/executors/webpack/lib/normalize-options"), exports);
-tslib_1.__exportStar(require("./src/executors/webpack/schema"), exports);
 tslib_1.__exportStar(require("./src/executors/webpack/webpack.impl"), exports);
 //# sourceMappingURL=index.js.map

Expected Behavior

Tests including @nrwl/webpack or its descendants should not fail (and .js files should not be attempting to export typescript)

Steps to Reproduce

Here's a minimal test that reproduces the issue. Also can be seen in this repo created with create-nx-plugin.

import { normalizePluginPath } from '@nrwl/webpack';

describe('@nrwl/webpack normalizePluginPath', () => {
  it('should return a defined value', async () => {
    expect(normalizePluginPath("test", "test")).toBeDefined();
  });
});

Running this test using npx nx test test results in the following error.

Failure Logs

  ● Test suite failed to run

    Cannot find module './src/executors/dev-server/schema' from '../../node_modules/@nrwl/webpack/index.js'

    Require stack:
      /Users/nikki/repro-nx-webpack-schema-bug/node_modules/@nrwl/webpack/index.js
      src/test.spec.ts


    However, Jest was able to find:
    	'src/executors/dev-server/schema.d.ts'
    	'src/executors/dev-server/schema.json'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['ts', 'js', 'html'].

    See https://jestjs.io/docs/configuration#modulefileextensions-arraystring

      at Resolver._throwModNotFoundError (../../node_modules/jest-runtime/node_modules/jest-resolve/build/resolver.js:491:11)
      at Object.<anonymous> (../webpack/index.ts:3:1)

Environment

 >  NX   Report complete - copy this into the issue template

   Node : 16.15.1
   OS   : darwin arm64
   npm  : 8.11.0
   
   nx : 14.7.8
   @nrwl/angular : Not Found
   @nrwl/cypress : Not Found
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.7.8
   @nrwl/eslint-plugin-nx : 14.7.8
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 14.7.8
   @nrwl/js : 14.7.8
   @nrwl/linter : 14.7.8
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : 14.7.8
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/workspace : 14.7.8
   typescript : 4.8.3
   ---------------------------------------
   Local workspace plugins:
         @repro-nx-webpack-schema-bug/test
   ---------------------------------------
   Community plugins:
         @nrwl/webpack: 14.7.8

hiddenist avatar Sep 21 '22 08:09 hiddenist