question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Doesn't work with "multiple files" import

See original GitHub issue

Describe the bug This code causes the “handle-import” babel plugin to break:

import(
  /* webpackInclude: /\.docs\.js$/, webpackChunkName: "whatever-[request]" */
  `__cwd/${path}`,
)

To Reproduce

  1. Include the snippet above in a code.
  2. Receive Module build failed: TypeError: Cannot read property '0' of undefined error from node_modules\next\dist\server\build\babel\plugins\handle-import.js:35:30

Expected behavior I’d expect Next.js to be able to handle this kind of import usage, as it’s supported by webpack. The old way to do the same, namely require.context, is not breaking like this (though it’s breaking in other ways, as I’ll bescribe in “additional context”).

System information

  • OS: Windows 10
  • Version of Next.js: 6.0.3

Additional context Related issue: https://github.com/zeit/next.js/issues/2690

This problem is directly caused by the “handle-import” plugin expecting the first argument to be a string literal (which has the value property). Since in my case it’s a template literal, it doesn’t have a value, only expressions and quasis.


For a while now I’ve been trying to create a wrapper around Next.js that’s able to work with dynamically imported files (a tool for documentation which includes all *.docs.js files in the project).

First of all, I can’t use pages/ - I want documentation files to be close to the scripts they document. I want the original structure of the source to be reflected by the structure of documentation, so replicating the directory structure in two places (original and pages) seems like an unmaintainable idea.

That’s how I arrived at a solution that uses import-all.macro. The problem with that is, it’s powered by babel. So when, as a user, I’m adding a new documentation file, I’ll need to stop the tool, purge the cache (since all imports are inlined in a file), and restart the tool. I’m losing the file-listening capabilities of webpack-dev-server, and I need to go around the limitations of babel caching.

That’s how I arrived at a solution that uses require.context. It almost works! I can’t get the SSR story correctly though - while the server renders the appropriate script, the chunk doesn’t seem to be ready when dynamic is rendering the component. Actually, the chunk doesn’t seem to be generated at all! That’s why I switched to import, to try and see if I could get the chunk-creating machine going at least with the other way of importing. As it is now, I’ve spent several days on this, I’m spinning in place, and I’m determined to fix the problem.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
timneutkenscommented, Jul 2, 2018

@fatfisz yep that’s what I’m working on, works great so far 👍

1reaction
timneutkenscommented, Jul 2, 2018

Will be fixed with #4639

Read more comments on GitHub >

github_iconTop Results From Across the Web

Common Mistakes When Dealing with Multiple Python Files
In this article, I am going to walk you through some common mistakes I've got trapped in and I hope you won't make...
Read more >
python - How to import multiple objects in different files easily
What you wrote would do it and there's no multi-module import ... module (not even separate directory) and just do from .folder import...
Read more >
6 Common CSV Import Errors and How to Fix Them
Here are the top CSV import issues that can cause major headaches when importing your files. · 1. File size · 2. Matching:...
Read more >
problem with Importing multiple files
StringForm is useful for embedding values into a control string: filestring[vals__] := ToString @ StringForm["mutomu,dms41,``,dms51,``,q24 ...
Read more >
Import data from a folder with multiple files (Power Query)
Use Excel's Get & Transform (Power Query) experience to combine multiple files, which have the same schema, from a single folder into a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found