Giter Site home page Giter Site logo

Comments (9)

Julian-B90 avatar Julian-B90 commented on June 10, 2024 3

I have the same error Cannot find module 'deepdash-es/omitDeep' from

from deepdash.

rommni avatar rommni commented on June 10, 2024

Same error here, someone has an idea how to fix this ?

from deepdash.

jonnytest1 avatar jonnytest1 commented on June 10, 2024

something along the lines of this in the jest-setup.js should work

const packageJsonPath = join(__dirname, 'node_modules/deepdash-es/package.json');
const packageJson = JSON.parse(readFileSync(packageJsonPath, { encoding: 'utf8' }));

// fix package.json

writeFileSync(packageJsonPath, JSON.stringify(packageJson, undefined, '  '));

from deepdash.

Dinika avatar Dinika commented on June 10, 2024

@jonnytest1 The above does not work in non-nodejs environments, right? At least I get the following errors:

ReferenceError: join is not defined                                // I fixed this by using Array.prototype.join
ReferenceError: readFileSync is not defined

I also don't completely understand the solution. It seems to me we are trying to change the contents of package.json file for deepdash-es module, which looks a bit hacky. Is there a better, more official way of handling this?

from deepdash.

Dinika avatar Dinika commented on June 10, 2024

My work around for the issue was the following:

// jest.config.js

  moduleNameMapper: {
    ... other mapping,
    'deepdash-es': '<rootDir>/global.mock.js', 
  },

// global.mock.js

// Mock implementations for deepdash-es functions being used by the component under test 
export const findDeep = (flatTree, findFn) => flatTree.find(findFn);
export const reduceDeep = (arr) => arr;

Obviously, the work-around is not great because it requires overriding functionality provided by this library that the component under test relies on, but at least jest is able to run the tests where I can test overall functionality of my react component.

from deepdash.

jonnytest1 avatar jonnytest1 commented on June 10, 2024

yeah the "fix" is definitely hacky , but i dont think thers a good way to do it - cleanest would probably be to fork the project and deploy it with the fix

from deepdash.

jonnytest1 avatar jonnytest1 commented on June 10, 2024
import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';

to get the methods - and well the fix implementation would still need some testing to add the property in exports

from deepdash.

Dinika avatar Dinika commented on June 10, 2024

@jonnytest1 Thanks for the comment. I did try the suggested solution but I still get the error Cannot find module 'deepdash-es/standalone' from path/to/component/that/uses/deepdash-es;

Here's my jest config:

// File - jest.config.js
const customJestConfig = {
    ... // Other config
      setupFiles: ['./global.mock.js'], // The file inside which I've added the suggested lines
      moduleNameMapper: {
            '^@/(.*)$': '<rootDir>/src/$1',
      },
}
module.exports = createJestConfig(customJestConfig);

And here's the setup file called global.mock.js

import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';

const packageJsonPath = join(__dirname, 'node_modules/deepdash-es/package.json');
const packageJson = JSON.parse(readFileSync(packageJsonPath, { encoding: 'utf8' }));

// fix package.json
writeFileSync(packageJsonPath, JSON.stringify(packageJson, undefined, '  '));

from deepdash.

jonnytest1 avatar jonnytest1 commented on June 10, 2024

the comment where it says "fix package.json" still needs an implementation i havent looked at it in details but i think it should be soemthing like

for(let export in packageJson.exports){
   if(!packageJson.exports[export]{
      packageJson.exports[export].require=export+".js
   }
}

or something similar , but the current package.json implementation over at https://github.com/YuriGor/deepdash/blob/master/package.json already seems to be correct , so maybe try to update to the latest version first maybe thers already a release for it

from deepdash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.