Skip to content
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

EJS: ReferenceError: include is not defined #1216

Closed
berkant opened this issue May 22, 2019 · 1 comment
Closed

EJS: ReferenceError: include is not defined #1216

berkant opened this issue May 22, 2019 · 1 comment

Comments

@berkant
Copy link

berkant commented May 22, 2019

Expected behaviour

Was expecting no errors and script to include the includee.

Current behaviour

ERROR in Template execution failed: ReferenceError: include is not defined

ERROR in   ReferenceError: include is not defined

Environment

Tell us which operating system you are using, as well as which versions of Node.js, npm, webpack, and html-webpack-plugin. Run the following to get it quickly:

Node.js v10.15.3
System: linux 4.18.0-17-generic
NPM v6.4.1
webpack@4.32.0
html-webpack-plugin@3.2.0

Config

Copy the minimal webpack.config.js to produce this issue:

module.exports = {
	entry: {
		index: './src/index/main.js',
		// privacy_policy: './src/privacy-policy/main.js'
	},

	output: {
		path: buildPath,
		filename: '[name].[hash:8].js'
	},

	optimization: {
		minimizer: [new OptimizeCSSAssetsPlugin()]
	},

	plugins: [
		// Cleans dist directory.
		new CleanWebpackPlugin(),

		// Perform actions as pre and post hooks.
		new FileManagerPlugin({
			onEnd: {
				delete: ['dist/*.js'],
				copy: [{ source: 'src/robots.txt', destination: 'dist/' }]
			}
		}),

		// Index Page
		new HtmlWebpackPlugin({
			// Don't include these assets in build artifacts.
			excludeAssets: [/.+\.js/],

			// HTML minify options:
			minify: {
				collapseWhitespace: true,
				removeComments: true,
				removeRedundantAttributes: true,
				removeScriptTypeAttributes: true,
				removeStyleLinkTypeAttributes: true,
				useShortDoctype: true
			},
			template: '!!ejs-loader!src/index/main.ejs',
			filename: 'index.html'
		}),

		new HtmlWebpackExcludeAssetsPlugin(),

		new MiniCssExtractPlugin({
			filename: 'bundle.[hash:8].css'
		}),
		
		// new webpack.ProvidePlugin({
		// 	_: 'underscore',
		// }),
	],

	module: {
		rules: [
			{
				test: /\.css$/,
				use: [MiniCssExtractPlugin.loader, 'css-loader']
			},
		]
	}
};

Copy your template file if it is part of this issue:

main.ejs:

<%- include('../components/top') %>

Relevant Links

  • If your project is public, link to the repo so we can investigate directly.
  • BONUS POINTS: Create a minimal reproduction and upload it to GitHub. This will get you the fastest support.

Additional context

I tried inlining the loader by doing: template: '!!ejs-loader!src/index/main.ejs' which failed. And also tried setting the loader in rules as below but failed as well:

{
	test: /\.ejs$/,
	use: 'ejs-loader',
}
@jantimon
Copy link
Owner

The ejs-loader does not provide a include function

@lock lock bot locked as resolved and limited conversation to collaborators Aug 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants