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.

Example doesn't work

See original GitHub issue

Hi, I’ve cloned repository. Installed dependencies in example folder. And when running yarn test I get:

Validation Error:

Module jest-preset-angular should have "jest-preset.js" or "jest-preset.json" file at the root.

I see that this file is in root. I’ve also copied it to example folder and example/src but same error appears.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
thymikeecommented, Apr 5, 2019

have you run yarn in both root and example/ directories?

0reactions
wthocommented, Apr 6, 2019
  • Works with yarn
    yarn install
    cd example
    yarn install
    yarn test
    
  • Does not work with npm by default
    npm install
    cd example
    npm install
    npm test
    
    Something like this will come up:
      ● Test suite failed to run
      Cannot find module 'core-js/es6/reflect' from 'setupJest.js'
    

The reason is the symlink strategy by npm. In the example folder itself peerDependencies like @angular/... or core-js are installed, but not in the root folder of the library. We do not need them there to publish and test the library.

When resolving dependencies, npm will only go UP and look for node_modules folders.

As the symlink created by npm links upwards to ../, and as core-js is referenced in the preset in the parent folder, it will start to look for this dependency in the root folder <repo>/node_modules and upwards, but not in <repo>/example/node_modules. But it is not installed there.

yarn handles the sitation different. It actually copies the whole parent folder into <repo>/example/node_modules/jest-preset-angular and therefore require('core-js') in the preset can find the dependency in `<repo>/example/node_modules/core-js.

There are four solutions if you want to try out the example app:

  • use yarn (install it using npm i -g yarn)
  • install a jest-preset-angular version from npm, as @webdevelopland suggested using npm i -D jest-preset-angular@latest
  • copy the root folder manually into example/node_modules using from inside example:
    rm node_modules/jest-preset-angular
    mkdir node_modules/jest-preset-angular
    cp -r ../AngularSnapshotSerializer.js ../HTMLCommentSerializer.js ../index.js ../InlineHtmlStripStylesTransformer.js ../jest-preset.js ../package.json ../setupJest.js ../zone-patch  node_modules/jest-preset-angular
    
Read more comments on GitHub >

github_iconTop Results From Across the Web

I don't know why this three.js example doesn't work
I'm currently using VS-Code & have two files : index.html and index.js By copying a simple example from threejs.org I can't seem to...
Read more >
Nextjs example SSR doesnt work. · Issue #1735 - GitHub
In the nextjs-supabase-auth example the SSR functionality doesn't work. I can't get it to work either. In the API where the cookie is...
Read more >
Example code does not work - Developing with Prismic
Hi community, I'm having problems getting the nextjs-starter-prismic-blog to work. The error is same as #52 issue.
Read more >
24+ Reasons Code Doesn't Work & How To Fix It - WP SITES
Discover the most common reasons your CSS or PHP doesn't work or breaks your site when it really does work properly.
Read more >
Request Form Example doesnt work - Appian Community
while in the interface parameters, that variable is empty: I tried to put the same structure....but it doesnt work, same error. So, after...
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