Skip to content

TypeError: Cannot destructure property 'assetPrefix' of 'this.context._documentProps' as it is undefined. #16162

Discussion options

You must be logged in to vote

assetPrefix now can be accessed via this.context directly as of v9.5.3 like:

class InlineStylesHead extends Head {
	getCssLinks: Head['getCssLinks'] = ({ allFiles }) => {
		const { assetPrefix } = this.context
		if (!allFiles || allFiles.length === 0) return null

		return allFiles
			.filter((file: any) => /\.css$/.test(file))
			.map((file: any) => (
				<style
					key={file}
					nonce={this.props.nonce}
					data-href={`${assetPrefix}/_next/${file}`}
					dangerouslySetInnerHTML={{
						__html: fs.readFileSync(path.join(process.cwd(), '.next', file), 'utf-8'),
					}}
				/>
			))
	}
}

Replies: 4 comments 9 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@deadcoder0904
Comment options

@JamesSingleton
Comment options

@deadcoder0904
Comment options

@deadcoder0904
Comment options

@jermainkaminski
Comment options

Comment options

You must be logged in to vote
2 replies
@deadcoder0904
Comment options

@deadcoder0904
Comment options

Comment options

You must be logged in to vote
2 replies
@willvlad
Comment options

@JamesSingleton
Comment options

Answer selected by deadcoder0904
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
6 participants