Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Error: Cannot find module './src/host' #1133

Closed
cedricduffournet opened this issue Nov 4, 2021 · 6 comments · Fixed by #1135
Closed

[Bug]: Error: Cannot find module './src/host' #1133

cedricduffournet opened this issue Nov 4, 2021 · 6 comments · Fixed by #1135
Labels
🐛 Bug Confirmed Bug is confirmed

Comments

@cedricduffournet
Copy link
Contributor

cedricduffournet commented Nov 4, 2021

Version

v11.0.0-rc.0

Steps to reproduce

  1. Clone this repo: github.com:thymikee/jest-preset-angular.git
  2. Go to the examples/example-app-v13 directory
cd examples/example-app-v13
  1. edit package.json file and change jest-preset-angular version from ^10.1.0 to 11.0.0-rc.0
  2. Install dependencies
yarn install
  1. run test
yarn test

Expected behavior

Tests run

Actual behavior

Error is thrown

ngcc-jest-processor: running ngcc
Error: Cannot find module './src/host'                                                                                  
Require stack: 
- /Users/<user>/Sites/jest-preset-angular/examples/example-app-v13/node_modules/jest-preset-angular/build/ngtsc/reflection/index.js
- /Users/<user>/Sites/jest-preset-angular/examples/example-app-v13/node_modules/jest-preset-angular/build/transformers/downlevel-ctor.js
- /Users/<user>/Sites/jest-preset-angular/examples/example-app-v13/node_modules/jest-preset-angular/build/compiler/ng-jest-compiler.js
- /Users/<user>/Sites/jest-preset-angular/examples/example-app-v13/node_modules/jest-preset-angular/build/ng-jest-transformer.js
- /Users/<user>/Sites/jest-preset-angular/examples/example-app-v13/node_modules/jest-preset-angular/build/index.js      
- /Users/<user>/Sites/jest-preset-angular/examples/example-app-v13/node_modules/jest-util/build/requireOrImportModule.js
- /Users/<user>/Sites/jest-preset-angular/examples/example-app-v13/node_modules/jest-util/build/index.js                
- /Users/<user>/Sites/jest-preset-angular/examples/example-app-v13/node_modules/jest-config/build/getCacheDirectory.js  
- /Users/<user>/Sites/jest-preset-angular/examples/example-app-v13/node_modules/jest-config/build/Defaults.js           
- /Users/<user>/Sites/jest-preset-angular/examples/example-app-v13/node_modules/jest-config/build/normalize.js          
- /Users/<user>/Sites/jest-preset-angular/examples/example-app-v13/node_modules/jest-config/build/index.js              
- /Users/<user>/Sites/jest-preset-angular/examples/example-app-v13/node_modules/jest-cli/build/init/index.js            
- /Users/<user>/Sites/jest-preset-angular/examples/example-app-v13/node_modules/jest-cli/build/cli/index.js             
- /Users/<user>/Sites/jest-preset-angular/examples/example-app-v13/node_modules/jest-cli/bin/jest.js                    
- /Users/<user>/Sites/jest-preset-angular/examples/example-app-v13/node_modules/jest/bin/jest.js                        
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)                                         
    at Function.Module._load (internal/modules/cjs/loader.js:745:27)                                                    
    at Module.require (internal/modules/cjs/loader.js:961:19)                                                           
    at require (internal/modules/cjs/helpers.js:92:18)                                                                  
    at Object.<anonymous> (/Users/<user>/Sites/jest-preset-angular/examples/example-app-v13/node_modules/jest-preset-angular/build/ngtsc/reflection/index.js:5:27)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)                                                         
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)                                           
    at Module.load (internal/modules/cjs/loader.js:937:32)                                                              
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)                                                    
    at Module.require (internal/modules/cjs/loader.js:961:19)  

Additional context

No response

Environment

npx : 1 installé(s) en 2.093s

  System:
    OS: macOS 11.6
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  Binaries:
    Node: 14.17.6 - ~/.nvm/versions/node/v14.17.6/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.15 - ~/.nvm/versions/node/v14.17.6/bin/npm
  npmPackages:
    jest: ^27.3.1 => 27.3.1
@Coly010
Copy link
Contributor

Coly010 commented Nov 4, 2021

I should have raised this last night! When doing my testing I noticed the src folder in ngtsc doesn't get included in the npm release anymore, causing the error above.

When doing local testing, I had to manually copy that folder (ngtsc/src) into the node_modules jest-preset-angular/build/ngtsc folder.

Using yarn link or npm link during local testing works because it symlinks the directory containing the correct files, but npm publish and yarn publish are not including that folder.

I'm not sure why it's no longer being included in the published bundle, but that is the cause of the error, and it'll likely cause problems for any consumer of the package.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Nov 4, 2021

Seem like this line https://github.com/thymikee/jest-preset-angular/blob/main/.npmignore#L6 did a recursive search and caused the problem.

@michaelfaith
Copy link
Contributor

I'm encountering this as well.

@michaelfaith
Copy link
Contributor

Thanks for the quick turnaround.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Nov 4, 2021

11.0.0-rc.1 was out, the problem should be fixed now

@michaelfaith
Copy link
Contributor

Can confirm. This fixed the issue we were seeing. But I'm now seeing another related to Angular Material initialization:

Test suite failed to run

    ReferenceError: Cannot access 'MatButtonToggle' before initialization

       6 |
       7 | import { ComponentFixture, TestBed } from '@angular/core/testing';
    >  8 | import { MatButtonToggleModule } from '@angular/material/button-toggle';
         | ^
       9 | import { MatIconModule } from '@angular/material/icon';
      10 |
      11 | import { ButtonToggleDemoComponent } from './button-toggle-demo.component';

      at Object.<anonymous> (../../node_modules/@angular/node_modules/@angular/material/fesm2015/button-toggle.mjs:254:63)
      at Object.<anonymous> (src/app/component-demos/button-toggle-demo/button-toggle-demo.component.spec.ts:8:1)

Guess I'll open a new issue for it.

It's happening with several Angular Material component modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Confirmed Bug is confirmed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants