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.

build fails with import statement in 3.1.6

See original GitHub issue

Describe the bug

npm run build fails to complete with v3.1.6 giving me the error “[plugin externalize-deps] Failed to resolve entry for package “fs”. The package may have incorrect main/module/exports specified in its package.json.” I resolved the problem by downgrading to Vite 3.1.4.

Reproduction

https://stackblitz.com/edit/vitejs-vite-rssden

System Info

System:
    OS: macOS 12.5.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 1.03 GB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 14.20.0 - ~/.nvm/versions/node/v14.20.0/bin/node
    npm: 6.14.17 - ~/.nvm/versions/node/v14.20.0/bin/npm
  npmPackages:
    @vitejs/plugin-vue: ^3.1.2 => 3.1.2
    vite: ^3.1.6 => 3.1.6

Used Package Manager

npm

Logs

ERROR] [plugin externalize-deps] Failed to resolve entry for package “fs”. The package may have incorrect main/module/exports specified in its package.json.

node_modules/esbuild/lib/main.js:1327:27:
  1327 │         let result = await callback({
       ╵                            ^

at packageEntryFailure (file:///Users/markbokil/dev/clinic-frx-delivery-log-ui/node_modules/vite/dist/node/chunks/dep-db16f19c.js:34841:11)
at resolvePackageEntry (file:///Users/markbokil/dev/clinic-frx-delivery-log-ui/node_modules/vite/dist/node/chunks/dep-db16f19c.js:34838:5)
at tryNodeResolve (file:///Users/markbokil/dev/clinic-frx-delivery-log-ui/node_modules/vite/dist/node/chunks/dep-db16f19c.js:34584:20)
at file:///Users/markbokil/dev/clinic-frx-delivery-log-ui/node_modules/vite/dist/node/chunks/dep-db16f19c.js:63459:44
at requestCallbacks.on-resolve (/Users/markbokil/dev/clinic-frx-delivery-log-ui/node_modules/esbuild/lib/main.js:1327:28)
at handleRequest (/Users/markbokil/dev/clinic-frx-delivery-log-ui/node_modules/esbuild/lib/main.js:697:19)
at handleIncomingPacket (/Users/markbokil/dev/clinic-frx-delivery-log-ui/node_modules/esbuild/lib/main.js:719:7)
at Socket.readFromStdout (/Users/markbokil/dev/clinic-frx-delivery-log-ui/node_modules/esbuild/lib/main.js:647:7)
at Socket.emit (events.js:400:28)
at addChunk (internal/streams/readable.js:293:12)

This error came from the “onResolve” callback registered here:

node_modules/esbuild/lib/main.js:1251:20:
  1251 │       let promise = setup({
       ╵                     ^

at setup (file:///Users/markbokil/dev/clinic-frx-delivery-log-ui/node_modules/vite/dist/node/chunks/dep-db16f19c.js:63456:27)
at handlePlugins (/Users/markbokil/dev/clinic-frx-delivery-log-ui/node_modules/esbuild/lib/main.js:1251:21)
at buildOrServeImpl (/Users/markbokil/dev/clinic-frx-delivery-log-ui/node_modules/esbuild/lib/main.js:942:5)
at Object.buildOrServe (/Users/markbokil/dev/clinic-frx-delivery-log-ui/node_modules/esbuild/lib/main.js:750:5)
at /Users/markbokil/dev/clinic-frx-delivery-log-ui/node_modules/esbuild/lib/main.js:2085:17
at new Promise (<anonymous>)
at Object.build (/Users/markbokil/dev/clinic-frx-delivery-log-ui/node_modules/esbuild/lib/main.js:2084:14)
at build (/Users/markbokil/dev/clinic-frx-delivery-log-ui/node_modules/esbuild/lib/main.js:1931:51)
at bundleConfigFile (file:///Users/markbokil/dev/clinic-frx-delivery-log-ui/node_modules/vite/dist/node/chunks/dep-db16f19c.js:63423:26)

The plugin “externalize-deps” was triggered by this import

vite.config.js:3:15:
  3 │ import fs from 'fs'

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mbokilcommented, Oct 8, 2022

No your analysis of the bug is incorrect. The fs import is needed by our business. Note that I had to include a minimal test case for the reproduction since I can’t add certs to the reproduction. This code below works in 3.1.4 but fails for anything after that. We use certs for HTTPS for Okta security.

import { fileURLToPath, URL } from 'url'
import { defineConfig } from 'vite'
import fs from 'fs'
import vue from '@vitejs/plugin-vue'
 
export default defineConfig({
  server: {
    https: {
      key: fs.readFileSync('./cert/key.pem'),
      cert: fs.readFileSync('./cert/cert.pem')
    }
  },
  plugins: [
                vue({})
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

ERROR on compilation Cannot use import statement outside ...
I have made my first own project and i try to build my app and launch it after compilation. When I ...
Read more >
Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import {...
Read more >
importlib — The implementation of import — Python 3.11.1 ...
One is to provide the implementation of the import statement (and thus, by extension, the __import__() function) in Python source code.
Read more >
3.1. Quickstart — Cabal 3.8.1.0 User's Guide
What does the package build: 1) Executable 2) Library 3) Library and Executable 4) Test suite Your ... Cabal files use “ --...
Read more >
Updates - CodeKit
Kit @import statements incorrectly ignored spaces in file paths. ... (There's a bug in the build process that causes crashes on 10.13 and...
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