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

Error: Cannot find module './_baseKeys' #353

Closed
throrin19 opened this issue Nov 8, 2022 · 5 comments
Closed

Error: Cannot find module './_baseKeys' #353

throrin19 opened this issue Nov 8, 2022 · 5 comments
Labels
need repro The issue needs a minimal reproduction to be fixed to triage This issue needs to be triaged

Comments

@throrin19
Copy link

throrin19 commented Nov 8, 2022

Describe the bug

After upgrade from 0.10.x to 0.11.6, I have weird problem on compilation phase of my project with histoire. I have this error for each my stories :

Error while collecting story /Users/user/Development/vue/manager-v2/stories/components/AqAvatar.story.vue:
Error: Cannot find module './_baseKeys'
Require stack:
- /Users/user/Development/vue/manager-v2/lodash/isEmpty
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at lodash/isEmpty:1:223
    at ViteNodeRunner.directRequest (file:///Users/user/Development/vue/manager-v2/node_modules/vite-node/dist/client.mjs:251:11)
    at async ViteNodeRunner.cachedRequest (file:///Users/user/Development/vue/manager-v2/node_modules/vite-node/dist/client.mjs:128:12)
    at async request (file:///Users/user/Development/vue/manager-v2/node_modules/vite-node/dist/client.mjs:151:16)
    at async /Users/user/Development/vue/manager-v2/src/configs.js:1:455
    at async ViteNodeRunner.directRequest (file:///Users/user/Development/vue/manager-v2/node_modules/vite-node/dist/client.mjs:251:5)

The only one file, in my code, shown in the stacktrace is my config.js file. It's just an js object return my application configuration (api link, ...) and it only load lodash/isEmpty like that :

import isEmpty from 'lodash/isEmpty';

export default {
    mode    : import.meta.env.MODE || 'local',
    commit  : import.meta.env.VITE_COMMIT,
    title   : import.meta.env.VITE_TITLE || 'Manager',
    locale  : {
        default     : 'en',
        availables  : ['en', 'fr'],
    },
    api         : {
        apikey  : import.meta.env.VITE_SERVERLESS_APIKEY,
        url     : import.meta.env.VITE_SERVERLESS_URL,
        version : isEmpty(import.meta.env.VITE_SERVERLESS_VERSION) ? undefined : `"${import.meta.env.VITE_SERVERLESS_VERSION || 'dev'}"`,
    },
};

The weird part is the pah used to load lodash/isEmpty : it seems not to search it in node_modules of the project but directly in the root of the project.

I have change anything between the 0.10.x and the 0.11.6 in my code and I don't have this problem with vite when I launch my project. Only with histoire with no reason.

Reproduction

I don't know if it's easilly reproductible, this is a large project :/

System Info

System:
    OS: macOS 12.6
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 1.80 GB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
    npm: 8.19.2 - ~/.nvm/versions/node/v16.15.0/bin/npm
  Browsers:
    Chrome: 107.0.5304.87
    Edge: 107.0.1418.35
    Firefox: 104.0.2
    Firefox Developer Edition: 69.0
    Safari: 16.0
  npmPackages:
    @histoire/plugin-vue: 0.11.6 => 0.11.6 
    @vitejs/plugin-vue: 3.2.0 => 3.2.0 
    histoire: 0.11.6 => 0.11.6 
    vite: 3.2.3 => 3.2.3 


### Used Package Manager

npm

### Validations

- [X] Follow our [Code of Conduct](https:/histoire-dev/histoire/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https:/histoire-dev/histoire/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://histoire.dev/guide/).
- [X] Check that there isn't [already an issue](https:/histoire-dev/histoire/issues) that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https:/histoire-dev/histoire/discussions).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
@throrin19 throrin19 added the to triage This issue needs to be triaged label Nov 8, 2022
@throrin19
Copy link
Author

After tests, it works fine in 0.10.7, the error occured with the 0.11.0+ version

@Akryum
Copy link
Member

Akryum commented Nov 11, 2022

A minimal repro using lodash would be needed to look for the cause.
From the informations you provided, it looks like lodash code is not valid standard ESM (it's missing the file extensions), so it has trouble running on Node. You can play with the viteNodeInlineDeps to work around this by forcing transpilation of the package.

@Akryum Akryum added the need repro The issue needs a minimal reproduction to be fixed label Nov 11, 2022
@throrin19
Copy link
Author

@Akryum But with vite, I have no problem. Only with histoire in the 0.11.x versions :/

I'll try to create a mini repo with this problem asap

@andrey-hohlov
Copy link

I faced the same issue

@andrey-hohlov
Copy link

andrey-hohlov commented Nov 16, 2022

I managed to reproduce this error with minimal setup https:/andrey-hohlov/histoire-lodash-bug

Error while collecting story /path/to/repo/histoire-bug/src/components/svg-icon/svg-icon.story.vue:
Error: Cannot find module './_baseMerge'

It happens only with this combination.

src/components/svg-icon is a wrapper for svg icons. We have a script that generates vue components from svg files. There is a story for this component and story uses generated icon component.

src/components/some-component - just some component. The thing is we also export from this folder a composable that uses lodash.

If I remove index file src/components/index.ts error doesn't happen.

With v0.10.7 it doesn't happen.

@Akryum Akryum closed this as completed in edf46b3 Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need repro The issue needs a minimal reproduction to be fixed to triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

3 participants