Skip to content

ERROR Template execution failed: TypeError: Cannot read property 'entry' of undefined #1492

@gabrielrtakeda

Description

@gabrielrtakeda

Do you want to request a feature or report a bug?

Maybe a bug...

What is the current behaviour?

After upgrading preact-cli to v3.0.4 I'm getting the error below, after running preact build

✖ ERROR Template execution failed: TypeError: Cannot read property 'entry' of undefined

If the current behaviour is a bug, please provide the steps to reproduce.

After adding the same changes of #1490 in my local node_modules preact-cli installation to be able to pass --no-prerender option properly, I've executed:

yarn preact build --no-sw --no-esm --no-prerender --no-inline-css

What is the expected behaviour?

Apparently it's building the code properly but, since the build script exists with code 1, it breaks CI the workflow..
(Also, it's generating a new file called 200.html)

image-preact-cli

Please mention other relevant information.

Opening the 200.html file it prints out the html below:

image

cat /var/folders/40/hmnm06wd6dv_q5pklkjdh5dc0000gn/T/preact-cli/template.tmp.ejs

Click to expand

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title><%= htmlWebpackPlugin.options.title %></title>
		<meta name="viewport" content="width=device-width,initial-scale=1">
		<meta name="mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<link rel="apple-touch-icon" href="/assets/icons/apple-touch-icon.png">
		<link rel="manifest" href="<%= htmlWebpackPlugin.files.publicPath %>manifest.json">
<% if (htmlWebpackPlugin.options.manifest.theme_color) { %>
	<meta name="theme-color" content="<%= htmlWebpackPlugin.options.manifest.theme_color %>">
<% } %>
<% const loadManifest = htmlWebpackPlugin.options.createLoadManifest(compilation.assets, webpack.namedChunkGroups);%>
<% const filesRegexp = htmlWebpackPlugin.options.inlineCss ? /\.(chunk\.\w{5}\.css|js)$/ : /\.(css|js)$/;%>
<% for (const file in loadManifest[htmlWebpackPlugin.options.url]) { %>
	<% if (htmlWebpackPlugin.options.preload && file && file.match(filesRegexp)) { %>
		<% /* crossorigin for main bundle as that is loaded from `<script type=module` tag, other lazy loaded bundles are from webpack so its not needed */ %>
		<link rel="preload" href="<%= htmlWebpackPlugin.files.publicPath + file %>" as="<%= file.match(/\.css$/)?'style':'script' %>" <%= file.match(/bundle\.\w{5}\.esm\.js$/)?'crossorigin="anonymous"':'' %>>
	<% } %>
<% } %>

	</head>
	<body>
		<%= htmlWebpackPlugin.options.ssr() %>
<script type="__PREACT_CLI_DATA__">
	<%= encodeURI(JSON.stringify(htmlWebpackPlugin.options.CLI_DATA)) %>
</script>
<% if (webpack.assets.filter(entry => entry.name.match(/bundle(\.\w{5})?.esm.js$/)).length > 0) { %>
	<% /* Fix for safari < 11 nomodule bug. TODO: Do the following only for safari. */ %>
	<script nomodule>!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()},!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();</script>
	<script crossorigin="anonymous" src="<%= htmlWebpackPlugin.files.publicPath %><%= webpack.assets.filter(entry => entry.name.match(/bundle(\.\w{5})?.esm.js$/))[0].name %>" type="module"></script>
	<%
		/*Fetch and Promise polyfills are not needed for browsers that support type=module
		Please re-evaluate below line if adding more polyfills.*/
	%>
	<script nomodule src="<%= htmlWebpackPlugin.files.chunks["polyfills"].entry %>"></script>
	<script nomodule defer src="<%= htmlWebpackPlugin.files.chunks['bundle'].entry %>"></script>
<% } else { %>
	<script <%= htmlWebpackPlugin.options.scriptLoading %>  src="<%= htmlWebpackPlugin.files.chunks['bundle'].entry %>"></script>
	<script nomodule src="<%= htmlWebpackPlugin.files.chunks["polyfills"].entry %>"></script>
<% } %>

	</body>
</html>

I'm not using a custom template so, I think it's related to the bump of ejs-loader from 0.37 to 0.5.0 in PR #1403

Please paste the results of preact info here.

Environment Info:
  System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  Binaries:
    Node: 14.11.0 - /var/folders/40/hmnm06wd6dv_q5pklkjdh5dc0000gn/T/yarn--1607536942927-0.1841710342107825/node
    Yarn: 1.22.10 - /var/folders/40/hmnm06wd6dv_q5pklkjdh5dc0000gn/T/yarn--1607536942927-0.1841710342107825/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v14.11.0/bin/npm
  Browsers:
    Chrome: 87.0.4280.88
    Firefox: 77.0.1
    Safari: 14.0.1
  npmPackages:
    preact: ^10.5.7 => 10.5.7
    preact-cli: ^3.0.4 => 3.0.4
    preact-render-to-string: ^5.1.12 => 5.1.12

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions