question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

vite build fails with CRLF endings in index.html: eof-in-element-that-can-contain-only-text

See original GitHub issue

Describe the bug

I have set git config --global core.autocrlf true so that on Linux my index.html has LF line endings and on Windows it has CRLF endings.

With LF line endings, vite build works perfectly, but on Windows with CRLF, I get the following error message:

vite v3.1.8 building for production...
✓ 0 modules transformed.
[vite:build-html] Unable to parse HTML; parse5 error code eof-in-element-that-can-contain-only-text
 at {"file":"H:/projekte/graph2/index.html","line":105,"column":1}

file: H:/projekte/graph2/index.html
error during build:
Error: Unable to parse HTML; parse5 error code eof-in-element-that-can-contain-only-text
 at {"file":"H:/projekte/graph2/index.html","line":105,"column":1}

    at handleParseError (file:///H:/projekte/graph2/node_modules/vite/dist/node/chunks/dep-4da11a5e.js:43393:11)
    at Parser.onParseError (file:///H:/projekte/graph2/node_modules/vite/dist/node/chunks/dep-4da11a5e.js:43320:13)
    at Parser._err (file:///H:/projekte/graph2/node_modules/vite/dist/node/chunks/dep-19c40c50.js:4942:14)
    at eofInText (file:///H:/projekte/graph2/node_modules/vite/dist/node/chunks/dep-19c40c50.js:6977:7)
    at Parser.onEof (file:///H:/projekte/graph2/node_modules/vite/dist/node/chunks/dep-19c40c50.js:5731:17)
    at Tokenizer._emitEOFToken (file:///H:/projekte/graph2/node_modules/vite/dist/node/chunks/dep-19c40c50.js:1403:22)
    at Tokenizer._stateRawtext (file:///H:/projekte/graph2/node_modules/vite/dist/node/chunks/dep-19c40c50.js:1903:22)
    at Tokenizer._callState (file:///H:/projekte/graph2/node_modules/vite/dist/node/chunks/dep-19c40c50.js:1522:22)
    at Tokenizer._runParsingLoop (file:///H:/projekte/graph2/node_modules/vite/dist/node/chunks/dep-19c40c50.js:1179:22)
    at Tokenizer.write (file:///H:/projekte/graph2/node_modules/vite/dist/node/chunks/dep-19c40c50.js:1204:14)

The error goes away when I convert the file from CRLF to LF in Notepad++.

Reproduction

git@github.com:snikproject/graph.git

Steps to reproduce

git clone git@github.com:snikproject/graph.git
cd graph
git checkout f9a450f966ac44c6f0fa1cfd7a5ba3d89fa6d32d
npm install
vite build

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (6) ia32 Intel(R) Core(TM) i5-9600 CPU @ 3.10GHz
    Memory: 10.54 GB / 15.79 GB
  Binaries:
    Node: 19.0.0 - H:\opt\node\node.EXE
    npm: 8.19.2 - H:\opt\node\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (106.0.1370.47)
    Internet Explorer: 11.0.19041.1566

Used Package Manager

npm

Logs

Click to expand!
  vite:config bundled config file loaded in 350.49ms +0ms
  vite:esbuild init tsconfck (root: H:/projekte/graph) +0ms
  vite:esbuild init tsconfck (root: H:/projekte/graph) +5ms
  vite:esbuild init tsconfck (root: H:/projekte/graph) +4ms
  vite:esbuild init tsconfck (root: H:/projekte/graph) +3ms
  vite:esbuild init tsconfck end +82ms
  vite:esbuild init tsconfck end +1ms
  vite:esbuild init tsconfck end +0ms
  vite:esbuild init tsconfck end +0ms
  vite:config using resolved config: {
  vite:config   base: './',
  vite:config   sourcemap: true,
  vite:config   build: {
  vite:config     target: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari13' ],
  vite:config     polyfillModulePreload: true,
  vite:config     outDir: 'dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     cssTarget: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari13' ],
  vite:config     sourcemap: false,
  vite:config     rollupOptions: { input: [Object], output: [Object] },
  vite:config     minify: 'esbuild',
  vite:config     terserOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     reportCompressedSize: true,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null,
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
  vite:config   },
  vite:config   test: { globals: true },
  vite:config   optimizeDeps: {
  vite:config     disabled: 'build',
  vite:config     force: undefined,
  vite:config     esbuildOptions: { preserveSymlinks: undefined }
  vite:config   },
  vite:config   configFile: 'H:/projekte/graph/vite.config.js',
  vite:config   configFileDependencies: [ 'H:/projekte/graph/vite.config.js' ],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     optimizeDeps: { force: undefined },
  vite:config     build: {}
  vite:config   },
  vite:config   root: 'H:/projekte/graph',
  vite:config   resolve: { alias: [ [Object], [Object] ] },
  vite:config   publicDir: 'H:\\projekte\\graph\\public',
  vite:config   cacheDir: 'H:\\projekte\\graph\\node_modules\\.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   ssr: {
  vite:config     format: 'esm',
  vite:config     target: 'node',
  vite:config     optimizeDeps: { disabled: true, esbuildOptions: [Object] }
  vite:config   },
  vite:config   isWorker: false,
  vite:config   mainConfig: null,
  vite:config   isProduction: true,
  vite:config   plugins: [
  vite:config     'vite:build-metadata',
  vite:config     'vite:pre-alias',
  vite:config     'alias',
  vite:config     'vite:modulepreload-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html-inline-proxy',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm-helper',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'vite:wasm-fallback',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:build-html',
  vite:config     'vite:worker-import-meta-url',
  vite:config     'vite:force-systemjs-wrap-complete',
  vite:config     'vite:watch-package-data',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'vite:asset-import-meta-url',
  vite:config     'vite:dynamic-import-vars',
  vite:config     'vite:import-glob',
  vite:config     'vite:build-import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:terser',
  vite:config     'vite:reporter',
  vite:config     'vite:load-fallback'
  vite:config   ],
  vite:config   server: {
  vite:config     preTransformRequests: true,
  vite:config     middlewareMode: false,
  vite:config     fs: { strict: true, allow: [Array], deny: [Array] }
  vite:config   },
  vite:config   preview: {
  vite:config     port: undefined,
  vite:config     strictPort: undefined,
  vite:config     host: undefined,
  vite:config     https: undefined,
  vite:config     open: undefined,
  vite:config     proxy: undefined,
  vite:config     cors: undefined,
  vite:config     headers: undefined
  vite:config   },
  vite:config   env: {
  vite:config     VITE_GIT_BRANCH_NAME: 'master',
  vite:config     VITE_GIT_COMMIT_DATE: '2022-10-10T13:20:11+02:00',
  vite:config     VITE_GIT_COMMIT_HASH: 'f9a450f966ac44c6f0fa1cfd7a5ba3d89fa6d32d',
  vite:config     VITE_GIT_LAST_COMMIT_MESSAGE: 'Only layout nodes, not all elements.',
  vite:config     BASE_URL: './',
  vite:config     MODE: 'production',
  vite:config     DEV: false,
  vite:config     PROD: true
  vite:config   },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     warnOnce: [Function: warnOnce],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen],
  vite:config     hasErrorLogged: [Function: hasErrorLogged]
  vite:config   },
  vite:config   packageCache: Map(0) { set: [Function (anonymous)] },
  vite:config   createResolver: [Function: createResolver],
  vite:config   worker: {
  vite:config     format: 'iife',
  vite:config     plugins: [
  vite:config       'vite:build-metadata',
  vite:config       'vite:pre-alias',
  vite:config       'alias',
  vite:config       'vite:modulepreload-polyfill',
  vite:config       'vite:resolve',
  vite:config       'vite:html-inline-proxy',
  vite:config       'vite:css',
  vite:config       'vite:esbuild',
  vite:config       'vite:json',
  vite:config       'vite:wasm-helper',
  vite:config       'vite:worker',
  vite:config       'vite:asset',
  vite:config       'vite:wasm-fallback',
  vite:config       'vite:define',
  vite:config       'vite:css-post',
  vite:config       'vite:build-html',
  vite:config       'vite:worker-import-meta-url',
  vite:config       'vite:force-systemjs-wrap-complete',
  vite:config       'vite:watch-package-data',
  vite:config       'commonjs',
  vite:config       'vite:data-uri',
  vite:config       'vite:asset-import-meta-url',
  vite:config       'vite:dynamic-import-vars',
  vite:config       'vite:import-glob',
  vite:config       'vite:build-import-analysis',
  vite:config       'vite:esbuild-transpile',
  vite:config       'vite:terser',
  vite:config       'vite:reporter',
  vite:config       'vite:load-fallback'
  vite:config     ],
  vite:config     rollupOptions: {},
  vite:config     getSortedPlugins: [Function: getSortedPlugins],
  vite:config     getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config   },
  vite:config   appType: 'spa',
  vite:config   experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
  vite:config   getSortedPlugins: [Function: getSortedPlugins],
  vite:config   getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config } +903ms
vite v3.1.8 building for production...
✓ 0 modules transformed.
[vite:build-html] Unable to parse HTML; parse5 error code eof-in-element-that-can-contain-only-text
 at {"file":"H:/projekte/graph/index.html","line":104,"column":8}

file: H:/projekte/graph/index.html
error during build:
Error: Unable to parse HTML; parse5 error code eof-in-element-that-can-contain-only-text
 at {"file":"H:/projekte/graph/index.html","line":104,"column":8}

    at handleParseError (file:///H:/projekte/graph/node_modules/vite/dist/node/chunks/dep-4da11a5e.js:43393:11)
    at Parser.onParseError (file:///H:/projekte/graph/node_modules/vite/dist/node/chunks/dep-4da11a5e.js:43320:13)
    at Parser._err (file:///H:/projekte/graph/node_modules/vite/dist/node/chunks/dep-19c40c50.js:4942:14)
    at eofInText (file:///H:/projekte/graph/node_modules/vite/dist/node/chunks/dep-19c40c50.js:6977:7)
    at Parser.onEof (file:///H:/projekte/graph/node_modules/vite/dist/node/chunks/dep-19c40c50.js:5731:17)
    at Tokenizer._emitEOFToken (file:///H:/projekte/graph/node_modules/vite/dist/node/chunks/dep-19c40c50.js:1403:22)
    at Tokenizer._stateRawtext (file:///H:/projekte/graph/node_modules/vite/dist/node/chunks/dep-19c40c50.js:1903:22)
    at Tokenizer._callState (file:///H:/projekte/graph/node_modules/vite/dist/node/chunks/dep-19c40c50.js:1522:22)
    at Tokenizer._runParsingLoop (file:///H:/projekte/graph/node_modules/vite/dist/node/chunks/dep-19c40c50.js:1179:22)
    at Tokenizer.write (file:///H:/projekte/graph/node_modules/vite/dist/node/chunks/dep-19c40c50.js:1204:14)

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
KonradHoeffnercommented, Oct 24, 2022

Here is the reproduction repository: https://github.com/KonradHoeffner/vite-bug-crlf

/tmp$ git clone https://github.com/konradhoeffner/vite-bug-crlf.git 
Cloning into 'vite-bug-crlf'...
remote: Enumerating objects: 12, done.
remote: Counting objects: 100% (12/12), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 12 (delta 2), reused 12 (delta 2), pack-reused 0
Receiving objects: 100% (12/12), 6.45 KiB | 6.45 MiB/s, done.
Resolving deltas: 100% (2/2), done.
/tmp$ cd vite-bug-crlf
vite-bug-crlf$ npm install

added 14 packages, and audited 15 packages in 553ms

4 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
vite-bug-crlf$ npm run build

> vite-bug-crlf@0.0.0 build
> vite build

vite v3.1.8 building for production...
✓ 0 modules transformed.
[vite:build-html] Unable to parse HTML; parse5 error code eof-in-element-that-can-contain-only-text
 at {"file":"/tmp/vite-bug-crlf/index.html","line":9,"column":1}

file: /tmp/vite-bug-crlf/index.html
error during build:
Error: Unable to parse HTML; parse5 error code eof-in-element-that-can-contain-only-text
 at {"file":"/tmp/vite-bug-crlf/index.html","line":9,"column":1}

    at handleParseError (file:///tmp/vite-bug-crlf/node_modules/vite/dist/node/chunks/dep-4da11a5e.js:43393:11)
    at Parser.onParseError (file:///tmp/vite-bug-crlf/node_modules/vite/dist/node/chunks/dep-4da11a5e.js:43320:13)
    at Parser._err (file:///tmp/vite-bug-crlf/node_modules/vite/dist/node/chunks/dep-19c40c50.js:4942:14)
    at eofInText (file:///tmp/vite-bug-crlf/node_modules/vite/dist/node/chunks/dep-19c40c50.js:6977:7)
    at Parser.onEof (file:///tmp/vite-bug-crlf/node_modules/vite/dist/node/chunks/dep-19c40c50.js:5731:17)
    at Tokenizer._emitEOFToken (file:///tmp/vite-bug-crlf/node_modules/vite/dist/node/chunks/dep-19c40c50.js:1403:22)
    at Tokenizer._stateRawtext (file:///tmp/vite-bug-crlf/node_modules/vite/dist/node/chunks/dep-19c40c50.js:1903:22)
    at Tokenizer._callState (file:///tmp/vite-bug-crlf/node_modules/vite/dist/node/chunks/dep-19c40c50.js:1522:22)
    at Tokenizer._runParsingLoop (file:///tmp/vite-bug-crlf/node_modules/vite/dist/node/chunks/dep-19c40c50.js:1179:22)
    at Tokenizer.write (file:///tmp/vite-bug-crlf/node_modules/vite/dist/node/chunks/dep-19c40c50.js:1204:14)
0reactions
sapphi-redcommented, Nov 3, 2022

Closing as it’s fixed in upstream. It will be fixed when the next version of parse5 is released.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[vite:build-html] Unable to parse html in build step · Issue #4067
my index.html is perfectly valid but my other dozen HTML files that we import as strings are not all valid (in syntax). [vite: ......
Read more >
LF will be replaced by CRLF in git - What is that and is it ...
Gives the following warnings for many files: The file will have its original line endings in your working directory. warning: LF will be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found