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

Chunk name mismatch for dynamic child directory import #331

Closed
akagomez opened this issue May 9, 2019 · 1 comment · Fixed by #332
Closed

Chunk name mismatch for dynamic child directory import #331

akagomez opened this issue May 9, 2019 · 1 comment · Fixed by #332
Labels

Comments

@akagomez
Copy link

akagomez commented May 9, 2019

🐛 Bug Report

Dynamic imports without a static directory name result in mismatched chunk names.

A reproduction of #220

To Reproduce

Import a file dynamically relative to the current module in a directly descendant child directory:

loadable(props => import(`./${props.letter}/file`))

Expected behavior

The chunk name created at build time should match the chunk name referenced at runtime.

Link to repl or repo (highly encouraged)

  1. Clone the forked loadable-components repo

  2. Checkout the branch chunk-name-mismatch-bug

  3. Run yarn install && yarn run build,

  4. Navigate to examples/server-side-rendering

  5. Run yarn install

  6. Run the example:

    $ yarn run dev
    yarn run v1.13.0
    $ nodemon src/server/main.js
    [nodemon] 1.19.0
    [nodemon] to restart at any time, enter `rs`
    [nodemon] watching: *.*
    [nodemon] starting `babel-node src/server/main.js`
    Server started http://localhost:9000
  7. Navigate to localhost:9000 in a browser and observe the error:

    Invariant Violation: loadable: cannot find G-file in stats
        at invariant (/Users/akagomez/Code/smooth-code/loadable-components/packages/component/dist/loadable.cjs.js:13:15)
        at ChunkExtractor.getChunkGroup (/Users/akagomez/Code/smooth-code/loadable-components/packages/server/lib/ChunkExtractor.js:188:36)
        at one (/Users/akagomez/Code/smooth-code/loadable-components/packages/server/lib/ChunkExtractor.js:211:31)
        at chunk (/Users/akagomez/Code/smooth-code/loadable-components/packages/server/lib/ChunkExtractor.js:38:70)
        at arrayMap (/Users/akagomez/Code/smooth-code/loadable-components/node_modules/lodash/_arrayMap.js:16:21)
        at map (/Users/akagomez/Code/smooth-code/loadable-components/node_modules/lodash/map.js:50:10)
        at flatMap (/Users/akagomez/Code/smooth-code/loadable-components/node_modules/lodash/flatMap.js:26:22)
        at getAssets (/Users/akagomez/Code/smooth-code/loadable-components/packages/server/lib/ChunkExtractor.js:38:52)
        at ChunkExtractor.getChunkAssets (/Users/akagomez/Code/smooth-code/loadable-components/packages/server/lib/ChunkExtractor.js:221:14)
        at ChunkExtractor.getMainAssets (/Users/akagomez/Code/smooth-code/loadable-components/packages/server/lib/ChunkExtractor.js:304:25)
    
  8. Confirm the chunk name referenced at runtime is missing from the build:

    $ ls public/dist/node/
    G-file-file.js      letters-A-css.js    letters-A.js        letters-C.js        letters-E.js        letters-Z-file.js   main.css
    letters-A-css.css   letters-A.css       letters-B.js        letters-D.js        letters-F.js        loadable-stats.json main.js
  9. Confirm the chunk name referenced at runtime is missing from loadable-stats.json:

    $ grep G-file public/dist/web/loadable-stats.json
        "G-file-file": "G-file-file.js",
          "name": "G-file-file.js",
            "G-file-file"
            "G-file-file"
        "G-file-file": {
            "G-file-file"
            "G-file-file.js"
@gregberge gregberge added the bug label May 9, 2019
@gregberge
Copy link
Owner

Hello @akagomez, I will check it, thanks for the detailed issue!

gregberge added a commit that referenced this issue May 12, 2019
gregberge added a commit that referenced this issue May 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants