Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,24 @@ export function createParseErrorInfo(
importer,
)}" to \`assetsInclude\` in your configuration.`

const htmlScriptNote =
`\n\nNote: If this code is inside an inline <script> in an HTML file, ` +
`the literal sequence \`</script>\` (even inside a string or template literal)` +
` will terminate the script early due to HTML parsing rules. This results in ` +
`truncated/invalid JS being passed to import analysis. To fix, escape the slash ` +
`like \`<\\/script>\` in the HTML source, break the sequence (e.g. \`"</" + "script>"\`), ` +
`or move the code to an external .js/.ts module.`

const isHtmlImporter = !!importer && /\.html?$/i.test(importer)

const finalMessage =
`Failed to parse source for import analysis because the content ` +
`contains invalid JS syntax. ` +
msg +
(isHtmlImporter ? htmlScriptNote : '')

return {
message:
`Failed to parse source for import analysis because the content ` +
`contains invalid JS syntax. ` +
msg,
message: finalMessage,
showCodeFrame: !probablyBinary,
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/environment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import colors from 'picocolors'
import type { FSWatcher } from '#dep-types/chokidar'
import type { FetchFunctionOptions, FetchResult } from 'vite/module-runner'
import type { FSWatcher } from '#dep-types/chokidar'
import { BaseEnvironment } from '../baseEnvironment'
import type {
EnvironmentOptions,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import colors from 'picocolors'
import chokidar from 'chokidar'
import launchEditorMiddleware from 'launch-editor-middleware'
import type { SourceMap } from 'rollup'
import type { ModuleRunner } from 'vite/module-runner'
import type { FSWatcher, WatchOptions } from '#dep-types/chokidar'
import type { Connect } from '#dep-types/connect'
import type { ModuleRunner } from 'vite/module-runner'
import type { CommonServerOptions } from '../http'
import {
httpServerStart,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/ssr/runtime/serverModuleRunner.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { existsSync, readFileSync } from 'node:fs'
import type { HotPayload } from '#types/hmrPayload'
import { ModuleRunner, createNodeImportMeta } from 'vite/module-runner'
import type {
ModuleEvaluator,
ModuleRunnerHmr,
ModuleRunnerOptions,
} from 'vite/module-runner'
import type { HotPayload } from '#types/hmrPayload'
import type { DevEnvironment } from '../../server/environment'
import type {
HotChannelClient,
Expand Down
Loading