-
Notifications
You must be signed in to change notification settings - Fork 3
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
Beta build not working in Storybook with Webpack 5 #43
Comments
I feel like I'm close with syntax like this: const {
TwingEnvironment,
TwingLoaderRelativeFilesystem,
} = require('twing');
const twing = new TwingEnvironment(
new TwingLoaderRelativeFilesystem(),
{ autoescape: false }
);
module.exports = import('drupal-twig-extensions/twing').then(
({ addDrupalExtensions }) => {
addDrupalExtensions(twing);
return twing;
}
); (I can successfully But twing-loader is throwing an error that must mean that the Promise stuff at the bottom isn't working as I'd hoped:
Tried some variations, including with an |
Yes, problem with above attempt is that it sets const {
TwingEnvironment,
TwingLoaderRelativeFilesystem,
} = require('twing');
const twing = new TwingEnvironment(
new TwingLoaderRelativeFilesystem(),
{ autoescape: false },
);
import('drupal-twig-extensions/twing').then(
({ addDrupalExtensions }) => {
addDrupalExtensions(twing);
}
);
module.exports = twing; But apparently the mutation occurs too late, because I get this error: To summarize the whole problem:
|
Yep. I've confirmed everything you said in your previous post. So, twing-loader is NOT compatible with Webpack 5. It says it requires Webpack 4 on the homepage. Which means Webpack 5 is probably using a backwards-compatiblity layer to get twing-loader to work using old-school webpack-4 APIs. And that explains why twing-loader can't handle ES Modules properly. The proper fix for this issue is to upgrade twing-loader to be Webpack 5 compatible. There is a PR mentioning Webpack 5 warnings, but the PR doesn't actually upgrade the APIs. And using that PR still results in this error:
I'm using Storybook with webpack 4 successfully (I set up that project in March 2021), but I want to use webpack 5 now that Storybook supports that. I think a quick work-around would be for drupal-twig-extensions to re-add Babel-compiled CommonJS files. |
Thanks for the response. FYI (in case you missed it), here is how I make twing-loader compatible with Webpack 5. |
@MichaelAllenWarner Please try 1.0.0-beta.4 and use CommonJS in the file that imports it. Thanks! |
@JohnAlbin That's great—thanks! |
(Following up on our conversation here.)
I've created a repo demonstrating the problem.
The master branch uses the alpha build of
drupal-twig-extensions
and works fine (clone repo, donpm install
, and thennpm run storybook
).The
dte-beta
branch uses the beta-3 build ofdrupal-twig-extensions
and doesn't work. Here is the ESM-ifiedtwing-environment.js
file for that branch, with some comments explaining the situation.I'm not sure exactly what Storybook and Webpack are doing under the hood here, but so far the only solution I've found is sticking with the alpha build.
The text was updated successfully, but these errors were encountered: