question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Current Behavior

Tests utilizing the @nrwl/webpack package fail because the index.js file in the built javascript 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

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

1reaction
joeflateaucommented, Sep 29, 2022

I ended up editing my jest config to transform @nrwl/webpack:

/* eslint-disable */
export default {
  displayName: 'app',
  preset: '../../jest.preset.js',
  globals: {
    'ts-jest': {
      tsconfig: '<rootDir>/tsconfig.spec.json',
    },
  },
  testTimeout: 30_000,
  transform: {
    '^.+\\.[tj]s$': 'ts-jest',
  },
  transformIgnorePatterns: ['/node_modules/(?!(@nrwl/webpack)/)'],
  moduleFileExtensions: ['ts', 'js', 'html', 'd.ts'],
  coverageDirectory: '../../coverage/packages/app',
};

1reaction
NikkiDelRossocommented, Sep 28, 2022

@joeflateau You can patch the package for now - just remove the two schema export lines from the index.js file of the @nrwl/webpack package.

I used yarn patch since I’m using yarn berry in my repo, but patch-package will work, too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Export all d.ts files from a single index.d.ts file - Stack Overflow
Problem is that if you do not export anything from types/event.d.ts then you get the file is not the module error .
Read more >
jest transformignorepatterns | The AI Search Engine You Control
I have a Nuxt app that runs with pnpm and I'd like to test it using Jest and the vee-validate library. I tried...
Read more >
Nx 15.3 — Standalone Projects, Vite, Task Graph and more!
Nx already visualizes your project graph, mapping the dependencies different projects have on one another through imports and exports in ...
Read more >
TypeScript Github Star Ranking at 2018/09/09
Microsoft/TypeScript 38737 TypeScript is a superset of JavaScript that ... 733 dts-gen creates starter TypeScript definition files for any ...
Read more >
Cannot find module" when using inline webpack loaders with ...
I also like typescript and webpack . Combining them is a joy. Thing is – I'd like to separate my html files from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found