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 fails when cjs module requires a module with "#" in its path

See original GitHub issue

Describe the bug

I have a dependency on pagedjs which depends on d which depends on es5-ext/string/#/contains. inside d module there is actually a require call that I thinks it fails inside vite contains = require("es5-ext/string/#/contains"); (!!!NOTICE # SIGN INSIDE REQUIRE!!!)

Reproduction

  1. add “pagedjs” version “0.1.43” to a vite project
  2. import some deps from pagedjs and use it
    import { Previewer } from 'pagedjs'
    
    // ... 
    
    const pagedjsPreviewer = new Previewer()
    pagedjsPreviewer.preview()
    
    // ...
    
  3. run npm run dev

System Info

  • vite version: 2.0.5
  • Operating System: Mac OS
  • Node version: v12.21.0
  • Package manager (npm/yarn/pnpm) and version: npm@6.14.11

Logs (Optional if provided reproduction)

Pre-bundling dependencies:
  pagedjs
  date-fns
  highcharts
  chunk
  object-treeify
(this will be run only when your dependencies or config have changed)
 > node_modules/d/index.js:7:30: error: Could not read from file: /Users/florinonciu/development/experiments/noc-reporting-tool-vite/node_modules/es5-ext/string/index.js#/contains
    7 │   , contains        = require("es5-ext/string/#/contains");
      ╵                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~

 > node_modules/event-emitter/pipe.js:4:29: error: Could not read from file: /Users/florinonciu/development/experiments/noc-reporting-tool-vite/node_modules/es5-ext/array/index.js#/remove
    4 │   , remove         = require('es5-ext/array/#/remove')
      ╵                              ~~~~~~~~~~~~~~~~~~~~~~~~

error when starting dev server:
Error: Build failed with 2 errors:
node_modules/d/index.js:7:30: error: Could not read from file: /Users/florinonciu/development/experiments/noc-reporting-tool-vite/node_modules/es5-ext/string/index.js#/contains
node_modules/event-emitter/pipe.js:4:29: error: Could not read from file: /Users/florinonciu/development/experiments/noc-reporting-tool-vite/node_modules/es5-ext/array/index.js#/remove
    at failureErrorWithLog (/Users/florinonciu/development/experiments/noc-reporting-tool-vite/node_modules/esbuild/lib/main.js:1177:15)
    at buildResponseToResult (/Users/florinonciu/development/experiments/noc-reporting-tool-vite/node_modules/esbuild/lib/main.js:913:32)
    at /Users/florinonciu/development/experiments/noc-reporting-tool-vite/node_modules/esbuild/lib/main.js:1008:20
    at /Users/florinonciu/development/experiments/noc-reporting-tool-vite/node_modules/esbuild/lib/main.js:559:9
    at handleIncomingPacket (/Users/florinonciu/development/experiments/noc-reporting-tool-vite/node_modules/esbuild/lib/main.js:648:9)
    at Socket.readFromStdout (/Users/florinonciu/development/experiments/noc-reporting-tool-vite/node_modules/esbuild/lib/main.js:526:7)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! noc-reporting-tool-vite@0.0.0 dev: `vite --debug serve src/frontend/monthly-report`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the noc-reporting-tool-vite@0.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/florinonciu/.npm/_logs/2021-03-02T23_13_45_296Z-debug.log

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:14
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

16reactions
benmccanncommented, Apr 9, 2021

This issue is impossible to search for because you can’t search #, so I’m leaving a comment here to make it easier to find. pound sign / number sign / hash sign 😄

2reactions
YufJicommented, Mar 8, 2021

check filePath has ‘?’ or ‘#’ does exists:

  if (postfixIndex > 0 && !fs.existsSync(fsPath.slice(0, postfixIndex+1))) {
    file = fsPath.slice(0, postfixIndex)
    postfix = fsPath.slice(postfixIndex)
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Vite
Note Vite supports using ES modules syntax in the config file even if the project is not using native Node ESM via type:...
Read more >
vite server with vuejs fails after opening project with WebStorm
json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. I am wondering what...
Read more >
Failed to load config from vite.config.js - Laracasts
I have a fresh Laravel installation with Jetstream/Interia but when I run 'npm install && npm run dev' I get the error 'failed...
Read more >
I got error Cannot find module 'node:path' when installing ...
you probably need to do npm install first. · Sure I run npm install firstly · I added my OS info · I'd...
Read more >
API - ESBuild
The cjs format stands for "CommonJS" and is intended to be run in node. It assumes the environment contains exports , require ,...
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