Comments (9)
I have the same error Cannot find module 'deepdash-es/omitDeep' from
from deepdash.
Same error here, someone has an idea how to fix this ?
from deepdash.
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.
@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.
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.
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.
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.
@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.
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)
- omitDeep changes input on empty array HOT 1
- omitDeep doesn't omit objects HOT 7
- ERR_PACKAGE_PATH_NOT_EXPORTED HOT 3
- how to remove values from json if they exist
- Feature Request Parent path
- filterDeep not working on deeply nested object HOT 2
- Working with promises HOT 2
- Frustrating that things like `pickDeep` and `filterDeep` can only return a nested structure HOT 3
- deepFilter keep parents
- ESM: IIterateeContext typescript interface not exposed
- findPathDeep doesn't return first Value path
- findDeep or findDeepValue - Return object that contains the key & value
- eachDeep with childrenPath == wrong parent, parent path etc
- Bug in documentation _.findDeep*
- findDeep return types problem HOT 3
- Add contributing docs HOT 1
- findDeep is not a function HOT 1
- explicit return values, why and how does this work HOT 1
- mapValuesDeep mutates the original object if `leavesOnly: false` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deepdash.