You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The next/dynamic import is failing in handle-import.js due to a preprocessed module name evaluating to undefined. Boiled down version of code:
// index.jsconstpreval_modulename=preval` module.exports = './hello-' + 'world';`;console.log(preval_modulename);// prints './hello-world'constDynamicComponent=dynamic(import(preval_modulename));// reduces to import(undefined)// .babelrc{"presets": ["next/babel"],"plugins": ["preval"]}
I have searched the issues of this repository and believe that this is not a duplicate.
Previous issues such as #2690 are similar, however I believe that the extra wrinkle of attempting to use preval warrants this as a new issue.
Expected Behavior
According to the babel docs plugins should operate prior to presets. For this reason, I expected the preval plugin to build a static string at build time which the import handler plugin can parse and register chunks as usual.
Current Behavior
Instead, the import call evaluates the preval expression as undefined, which causes the dynamic import to fail. Interestingly, a console.log of the preval value does produce the correct value, not undefined. I expect this is due to a nuance of Babel's AST and the interaction between the plugins which I do not understand.
Cannot read property '0' of undefined at getModulePath (.../node_modules/next/dist/server/build/babel/plugins/handle-import.js:34:30)
Because the gallery will be added to indefinitely, I wish for each to be dynamically loaded independently without manually adding them as separate dynamic imports:
constFirst=dynamic(import('../gallery/first-component'));constAnother=dynamic(import('../gallery/another-component'));constYetAnother=dynamic(import('../gallery/yet-another-component'));constMore=dynamic(import('../gallery/more-component'));constYetMore=dynamic(import('../gallery/yet-more-component'));// continue indefinitely// is manual and error prone vsconstDirectoryBundle=dynamic({modules: props=>{constcomponents=preval`getDirectoryComponents()`;returncomponents},render: (props,components)=>// ...})
The Webpack docs discuss requiring with an expression however I have been unsuccessful in my attempts to hybridize this with next/dynamic.
Your Environment
Tech
Version
next
3.2.2
node
8.5.0
OS
Linux 4.10.0-33-generic
browser
Chrome 61.0.3163.91 (Official Build) (64-bit)
The text was updated successfully, but these errors were encountered:
CrockAgile
changed the title
Dynamic Imports using preval module path
Dynamic imports using preval module path
Sep 16, 2017
It sounds like the import is attempting to be evaluated before babel gets run, which might be a webpack thing? I'm unsure as to how webpack evaluates dynamic imports, but static imports definitely get run before any javascript is evaluated. I assumed that dynamic imports would run alongside the JavaScript, but I don't know the spec, and I don't know how webpack runs it, but perhaps that would be a good place to start looking.
The
next/dynamic
import is failing in handle-import.js due to a preprocessed module name evaluating toundefined
. Boiled down version of code:Previous issues such as #2690 are similar, however I believe that the extra wrinkle of attempting to use preval warrants this as a new issue.
Expected Behavior
According to the babel docs plugins should operate prior to presets. For this reason, I expected the preval plugin to build a static string at build time which the import handler plugin can parse and register chunks as usual.
Current Behavior
Instead, the import call evaluates the
preval
expression asundefined
, which causes the dynamic import to fail. Interestingly, aconsole.log
of thepreval
value does produce the correct value, notundefined
. I expect this is due to a nuance of Babel's AST and the interaction between the plugins which I do not understand.Steps to Reproduce (for bugs)
preval
expression toimport()
Context
I am building a gallery of components, with a directory of components:
Because the gallery will be added to indefinitely, I wish for each to be dynamically loaded independently without manually adding them as separate dynamic imports:
The Webpack docs discuss requiring with an expression however I have been unsuccessful in my attempts to hybridize this with
next/dynamic
.Your Environment
The text was updated successfully, but these errors were encountered: