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

Cannot find module './build/Release/DTraceProviderBindings' from 'dtrace-provider.js' #63

Closed
felipecao opened this issue Jul 6, 2017 · 11 comments
Assignees

Comments

@felipecao
Copy link

Hello everyone!

I wanted to create a really simple React app and add a Pact test on top of it, but I'm having some trouble making Pact play along well with Jest.

So i started by using https://github.com/facebookincubator/create-react-app to create that React app. It generates a small React app containing basically two classes under /src: App.js & App.test.js. If I run npm test, everything runs smooth.

Then I ran npm install --save-dev pact to install Pact.

Next thing I did was editing App.test.js to just import Pact, nothing else, this is how the test looks like:

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

import pact from 'pact'; // this is the only change I introduced

it('renders without crashing', () => {
  const div = document.createElement('div');
  ReactDOM.render(<App />, div);
});

Now if I run npm test again, the test crashes with this error message:

  console.error node_modules/dtrace-provider/dtrace-provider.js:26
    { Error: Cannot find module './build/Release/DTraceProviderBindings' from 'dtrace-provider.js'
        at Resolver.resolveModule (/Users/felipe/workspace/lixao/pact-js-react-issue/node_modules/jest-resolve/build/index.js:179:17)
        at Resolver._getVirtualMockPath (/Users/felipe/workspace/lixao/pact-js-react-issue/node_modules/jest-resolve/build/index.js:296:23)
        at Resolver._getAbsolutPath (/Users/felipe/workspace/lixao/pact-js-react-issue/node_modules/jest-resolve/build/index.js:279:10)
        at Resolver.getModuleID (/Users/felipe/workspace/lixao/pact-js-react-issue/node_modules/jest-resolve/build/index.js:252:31)
        at Runtime._shouldMock (/Users/felipe/workspace/lixao/pact-js-react-issue/node_modules/jest-runtime/build/index.js:574:37)
        at Runtime.requireModuleOrMock (/Users/felipe/workspace/lixao/pact-js-react-issue/node_modules/jest-runtime/build/index.js:402:14)
        at Object.<anonymous> (/Users/felipe/workspace/lixao/pact-js-react-issue/node_modules/dtrace-provider/dtrace-provider.js:17:23)
        at Runtime._execModule (/Users/felipe/workspace/lixao/pact-js-react-issue/node_modules/jest-runtime/build/index.js:513:13)
        at Runtime.requireModule (/Users/felipe/workspace/lixao/pact-js-react-issue/node_modules/jest-runtime/build/index.js:329:14)
        at Runtime.requireModuleOrMock (/Users/felipe/workspace/lixao/pact-js-react-issue/node_modules/jest-runtime/build/index.js:405:19) code: 'MODULE_NOT_FOUND' }

Am I doing anything wrong here?

I tried npm install --save dtrace-provider but that didn't change anything. I've also tried doing what's documented at https://github.com/pact-foundation/pact-js#note-on-jest, and no luck.

Thanks a lot for the excelent work with the whole Pact family!

@jonathanconway
Copy link

Having the same issue here.

@mefellows mefellows self-assigned this Jul 8, 2017
@mefellows mefellows added bug Indicates an unexpected problem or unintended behavior and removed Triage labels Jul 8, 2017
@mefellows
Copy link
Member

Cool, I have been able to repro this. Marking as bug.

For me the tests still work, this is more of an annoying output. Seemingly this issue is quite frequent.

I'm guessing it's related to pact-node which uses bunyan under the hood.

@mefellows
Copy link
Member

Upon investigation, it seems that bunyan has an optional dependency on dtrace-provider which doesn't seem to reliably compile/work on OSX. This appears to be a very common issue related to the dtrace provider.

As you can see, when installing pact it comes along for the ride:

npm i pact
...
my-app@0.1.0 /private/tmp/my-app
├── node-pre-gyp@0.6.36
└─┬ pact@2.6.0
  └─┬ @pact-foundation/pact-node@4.10.0
    ├─┬ @pact-foundation/pact-mock-service@2.1.0
    │ └── @pact-foundation/pact-mock-service-darwin@2.1.0
    ├─┬ @pact-foundation/pact-provider-verifier@1.3.0
    │ └── @pact-foundation/pact-provider-verifier-darwin@1.3.0
    └─┬ bunyan@1.8.10
      └── dtrace-provider@0.8.3

I've tried all of the suggestions and nothing worked, manually running the compilation didn't fail aside from a few spurious warnings and created what looked like bindings, just not in the intended location.

This workaround worked for me, although it's an obviously crappy solution:

npm uninstall bunyan && npm i bunyan --no-optional

Curious though, I'm not sure why specifically in this configuration it warns.

@mefellows mefellows added enhancement and removed bug Indicates an unexpected problem or unintended behavior labels Jul 8, 2017
@felipecao
Copy link
Author

felipecao commented Jul 10, 2017

I figured out that to work around this issue we just need to create a separate script, one that ignores Jest all together.

What I did was moving my Pact tests to src/pacts and then added a script to my package.json, like this:

"scripts": {
    ... 
    "pacts": "BABEL_ENV=pacts ./node_modules/.bin/mocha --recursive --compilers js:babel-core/register \"pacts/**/*.pact.js\" --timeout 10000"
  },

Then, if I run npm run pacts, my Pact tests run fine and I don't need to change anything for the tests created by create-react-app to work.

@mefellows
Copy link
Member

Thanks @felipecao, great find - I'll update the docs with this (somewhere).

@kevinbader
Copy link

kevinbader commented Jan 8, 2018

@mefellows, please re-open this, the error is still there. Also, the bunyan issue is open since January 2015, so I guess the best solution would be to get rid of the dependency, if possible (haven't checked the code yet).

Steps to reproduce:

  • Copy the official Jest example
  • Replace the Pact import in the test with const Pact = require('@pact-foundation/pact')
  • Install Pact and invoke tests:
yarn add --dev @pact-foundation/pact
yarn test

=> the reported "DTraceProviderBindings" error appears.

@mefellows
Copy link
Member

The issue is in upstream pact-node package - perhaps we need to look at removing it from there.

@mefellows mefellows reopened this Jan 11, 2018
@mefellows
Copy link
Member

cc: @mboudreau

@mefellows
Copy link
Member

mefellows commented Feb 28, 2018

Released v5.7.0 with this change @mbark.

@mbark
Copy link

mbark commented Feb 28, 2018

Thank you for the fast merge, everything looks good now! ⭐️

@mefellows
Copy link
Member

👍

blackbaud-joshlandi pushed a commit to blackbaud-joshlandi/pact-js that referenced this issue Mar 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants