indutny / webpack-common-shake

CommonJS Tree Shaker plugin for WebPack
918 stars 13 forks source link

Handle stage-3 dyanmic import. #2

Closed TheLarkInn closed 7 years ago

TheLarkInn commented 7 years ago

Here is the Code snippet from which I'm 100% sure this came from:

const asyncRenderView = (viewName, wire, model) =>
  import(`../../shared/view/${viewName}.js`).then(renderFn => renderFn(wire, model));

const view = {
  about: (wire, model) => asyncRenderView('about', wire, model),
  summary: (wire, model) => asyncRenderView('summary', wire, model),
  item: (wire, model) => asyncRenderView('item', wire, model),
  comment: (wire, model) => asyncRenderView('comment', wire, model),
  user: (wire, model) => asyncRenderView('user', wire, model),
  next: (wire, model) => asyncRenderView('next', wire, model)
};

Following error:

ERROR in ./client/js/render.js
Module parse failed: /Users/req88847/Code/@viper/viper-news/node_modules/babel-loader/lib/index.js!/Users/req88847/Code/@viper/viper-news/client/js/render.js Unknown node type Import.
You may need an appropriate loader to handle this file type.
Error: Unknown node type Import.
    at Controller.traverse (/Users/req88847/Code/@viper/viper-news/node_modules/estraverse/estraverse.js:521:31)
    at Object.traverse (/Users/req88847/Code/@viper/viper-news/node_modules/estraverse/estraverse.js:713:27)
    at Analyzer.sift (/Users/req88847/Code/@viper/viper-news/node_modules/common-shake/lib/shake/analyzer.js:177:14)
    at Analyzer.run (/Users/req88847/Code/@viper/viper-news/node_modules/common-shake/lib/shake/analyzer.js:35:8)
    at Parser.parser.plugin (/Users/req88847/Code/@viper/viper-news/node_modules/webpack-common-shake/lib/shake/plugin.js:17:19)
    at Parser.applyPluginsBailResult (/Users/req88847/Code/@viper/viper-news/node_modules/tapable/lib/Tapable.js:109:27)
    at Parser.parse (/Users/req88847/Code/@viper/viper-news/node_modules/webpack/lib/Parser.js:1366:11)
    at doBuild (/Users/req88847/Code/@viper/viper-news/node_modules/webpack/lib/NormalModule.js:293:17)
    at runLoaders (/Users/req88847/Code/@viper/viper-news/node_modules/webpack/lib/NormalModule.js:207:11)
    at /Users/req88847/Code/@viper/viper-news/node_modules/loader-runner/lib/LoaderRunner.js:370:3
    at iterateNormalLoaders (/Users/req88847/Code/@viper/viper-news/node_modules/loader-runner/lib/LoaderRunner.js:211:10)
    at iterateNormalLoaders (/Users/req88847/Code/@viper/viper-news/node_modules/loader-runner/lib/LoaderRunner.js:218:10)
    at /Users/req88847/Code/@viper/viper-news/node_modules/loader-runner/lib/LoaderRunner.js:233:3
    at Object.context.callback (/Users/req88847/Code/@viper/viper-news/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at Object.module.exports (/Users/req88847/Code/@viper/viper-news/node_modules/babel-loader/lib/index.js:183:8)
    at LOADER_EXECUTION (/Users/req88847/Code/@viper/viper-news/node_modules/loader-runner/lib/LoaderRunner.js:119:14)
    at runSyncOrAsync (/Users/req88847/Code/@viper/viper-news/node_modules/loader-runner/lib/LoaderRunner.js:120:4)
    at iterateNormalLoaders (/Users/req88847/Code/@viper/viper-news/node_modules/loader-runner/lib/LoaderRunner.js:229:2)
    at Array.<anonymous> (/Users/req88847/Code/@viper/viper-news/node_modules/loader-runner/lib/LoaderRunner.js:202:4)
    at Storage.finished (/Users/req88847/Code/@viper/viper-news/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:15)
    at /Users/req88847/Code/@viper/viper-news/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:69:9
    at /Users/req88847/Code/@viper/viper-news/node_modules/graceful-fs/graceful-fs.js:78:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:439:3)
 @ ./client/js/index.js 2:13-32

This is most likely because of the acorn dynamic-import plugin we are using so users can support import().

TheLarkInn commented 7 years ago

Ahh this is a more complex one because this is a ContextModule beacuse it has a partial path in the "dependency" statement.

indutny commented 7 years ago

Hopefully fixed in v1.0.0-alpha2, please give it a try.

indutny commented 7 years ago

This should be fixed now. Thanks again!

TheLarkInn commented 7 years ago

Thank you!!!!!!