Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error: Received '\x00__vite-browser-external?commonjs-proxy' #8469

Closed
7 tasks done
niczero opened this issue Jun 4, 2022 · 9 comments
Closed
7 tasks done

Build error: Received '\x00__vite-browser-external?commonjs-proxy' #8469

niczero opened this issue Jun 4, 2022 · 9 comments

Comments

@niczero
Copy link

niczero commented Jun 4, 2022

Describe the bug

I am seeing a build error when working on a project of Inertia + Svelte using Vite. The code works fine in development mode with HMR, but shows this error when doing a production build.

2022-06-03T07:28:49.338Z vite:vite-plugin-svelte error trying to resolve __vite-browser-external from __vite-browser-external?commonjs-proxy via package.json svelte field  TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received '\x00__vite-browser-external?commonjs-proxy'
    at new NodeError (node:internal/errors:372:5)
    at createRequire (node:internal/modules/cjs/loader:1220:13)
    at resolveViaPackageJsonSvelte ($DIR/vite-plugin-svelte-bug/node_modules/@sveltejs/vite-plugin-svelte/dist/index.cjs:1476:59)
    at Object.resolveId ($DIR/vite-plugin-svelte-bug/node_modules/@sveltejs/vite-plugin-svelte/dist/index.cjs:1728:28)
    at $DIR/vite-plugin-svelte-bug/node_modules/rollup/dist/shared/rollup.js:22974:37 {
  code: 'ERR_INVALID_ARG_VALUE'
}

Assets are produced in the dist dir, but the build is broken. The run-time error is actually in the object-inspect package.

The run-time error may simply be a consequence of the build error (I don't know), but in case it's relevant, the run-time error is:

Cannot read properties of undefined (reading 'custom')

and points to the line https://github.com/inspect-js/object-inspect/blob/2cba8e119af13ff9648d5160871c3da22948ca8a/index.js#L69 where require('./util.inspect') is resulting in undefined.
This run-time error is pretty much identical to #2598 but that was closed as resolved a year ago and I'm using all-up-to-date packages.

For the build error, I have tried substituting redaxios in place of axios, but the error message remained the same.
The repo has a strange name because I originally reported this under sveltejs/vite-plugin-svelte#362 but it looks like this is not a svelte problem but perhaps how vite handles cjs.

Reproduction

For the build error I have a minimal repro repo at https://github.com/niczero/vite-plugin-svelte-bug

System Info

System:
    OS: Linux 5.13 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (12) x64 Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
    Memory: 25.71 GB / 30.96 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 18.3.0 - /usr/bin/node
    npm: 8.11.0 - /usr/bin/npm
  Browsers:
    Chrome: 102.0.5005.61
    Firefox: 100.0.2
  npmPackages:
    vite: ^2.9.9 => 2.9.9

Used Package Manager

pnpm

Logs

[$DIR is just where I have redacted the path prefix]

> vite-build-bug@ build $DIR/vite-plugin-svelte-bug
> vite build --debug

2022-06-04T19:58:00.383Z vite:config bundled config file loaded in 57.23ms
2022-06-04T19:58:00.384Z vite:vite-plugin-svelte svelte inspector path: $DIR/vite-plugin-svelte-bug/node_modules/.pnpm/@sveltejs+vite-plugin-svelte@1.0.0-next.47_svelte@3.48.0+vite@2.9.9/node_modules/@sveltejs/vite-plugin-svelte/src/ui/inspector/
2022-06-04T19:58:00.385Z vite:vite-plugin-svelte no svelte config found at $DIR/vite-plugin-svelte-bug
2022-06-04T19:58:00.385Z vite:vite-plugin-svelte findSvelteDependencies: searching svelte dependencies in $DIR/vite-plugin-svelte-bug
2022-06-04T19:58:00.386Z vite:vite-plugin-svelte additional vite config {
  resolve: {
    mainFields: [ 'svelte', 'module', 'jsnext:main', 'jsnext' ],
    dedupe: [
      'svelte/animate',
      'svelte/easing',
      'svelte/internal',
      'svelte/motion',
      'svelte/ssr',
      'svelte/store',
      'svelte/transition',
      'svelte',
      'svelte-hmr/runtime/hot-api-esm.js',
      'svelte-hmr/runtime/proxy-adapter-dom.js',
      'svelte-hmr'
    ]
  },
  optimizeDeps: { extensions: [ '.svelte' ], esbuildOptions: { plugins: [Array] } },
  ssr: { noExternal: [] }
}
2022-06-04T19:58:00.394Z vite:vite-plugin-svelte resolved options {
  hot: false,
  compilerOptions: { css: false, dev: false },
  extensions: [ '.svelte' ],
  emitCss: true,
  experimental: { prebundleSvelteLibraries: true },
  root: '$DIR/vite-plugin-svelte-bug',
  isBuild: true,
  isServe: false,
  isDebug: true,
  isProduction: true
}
2022-06-04T19:58:00.396Z vite:config using resolved config: {
  build: {
    target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
    polyfillModulePreload: true,
    outDir: 'dist',
    assetsDir: 'assets',
    assetsInlineLimit: 4096,
    cssCodeSplit: true,
    cssTarget: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
    sourcemap: false,
    rollupOptions: { input: [Array] },
    minify: 'esbuild',
    terserOptions: {},
    write: true,
    emptyOutDir: null,
    manifest: false,
    lib: false,
    ssr: false,
    ssrManifest: false,
    reportCompressedSize: true,
    chunkSizeWarningLimit: 500,
    watch: null,
    commonjsOptions: { include: [Array], extensions: [Array] },
    dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
  },
  plugins: [
    'vite:build-metadata',
    'alias',
    'vite-plugin-svelte',
    'vite:modulepreload-polyfill',
    'vite:resolve',
    'vite:html-inline-proxy',
    'vite:css',
    'vite:esbuild',
    'vite:json',
    'vite:wasm',
    'vite:worker',
    'vite:asset',
    'vite:define',
    'vite:css-post',
    'vite:build-html',
    'vite:worker-import-meta-url',
    'vite:watch-package-data',
    'commonjs',
    'vite:data-uri',
    'rollup-plugin-dynamic-import-variables',
    'vite:asset-import-meta-url',
    'vite:build-import-analysis',
    'vite:esbuild-transpile',
    'vite:terser',
    'vite:reporter',
    'vite:load-fallback'
  ],
  resolve: {
    dedupe: [
      'svelte/animate',
      'svelte/easing',
      'svelte/internal',
      'svelte/motion',
      'svelte/ssr',
      'svelte/store',
      'svelte/transition',
      'svelte',
      'svelte-hmr/runtime/hot-api-esm.js',
      'svelte-hmr/runtime/proxy-adapter-dom.js',
      'svelte-hmr'
    ],
    mainFields: [ 'svelte', 'module', 'jsnext:main', 'jsnext' ],
    alias: [ [Object], [Object] ]
  },
  optimizeDeps: {
    extensions: [ '.svelte' ],
    esbuildOptions: {
      keepNames: undefined,
      preserveSymlinks: undefined,
      plugins: [Array]
    }
  },
  ssr: { noExternal: [] },
  configFile: '$DIR/vite-plugin-svelte-bug/vite.config.js',
  configFileDependencies: [
    '$DIR/vite-plugin-svelte-bug/vite.config.js'
  ],
  inlineConfig: {
    root: undefined,
    base: undefined,
    mode: undefined,
    configFile: undefined,
    logLevel: undefined,
    clearScreen: undefined,
    build: {}
  },
  root: '$DIR/vite-plugin-svelte-bug',
  base: '/',
  publicDir: '$DIR/vite-plugin-svelte-bug/public',
  cacheDir: '$DIR/vite-plugin-svelte-bug/node_modules/.vite',
  command: 'build',
  mode: 'production',
  isWorker: false,
  isProduction: true,
  server: {
    preTransformRequests: true,
    fs: { strict: true, allow: [Array], deny: [Array] }
  },
  preview: {
    port: undefined,
    strictPort: undefined,
    host: undefined,
    https: undefined,
    open: undefined,
    proxy: undefined,
    cors: undefined,
    headers: undefined
  },
  env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  assetsInclude: [Function: assetsInclude],
  logger: {
    hasWarned: false,
    info: [Function: info],
    warn: [Function: warn],
    warnOnce: [Function: warnOnce],
    error: [Function: error],
    clearScreen: [Function: clearScreen],
    hasErrorLogged: [Function: hasErrorLogged]
  },
  packageCache: Map(0) { set: [Function (anonymous)] },
  createResolver: [Function: createResolver],
  worker: {
    format: 'iife',
    plugins: [
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object]
    ],
    rollupOptions: {}
  }
}
vite v2.9.9 building for production...
transforming...
2022-06-04T19:58:00.524Z vite:vite-plugin-svelte transform returns compiled js for $DIR/vite-plugin-svelte-bug/node_modules/.pnpm/@inertiajs+inertia-svelte@0.8.0_fbnkmlyyx5hz7ybarl5bnfzfbq/node_modules/@inertiajs/inertia-svelte/src/App.svelte
2022-06-04T19:58:00.557Z vite:vite-plugin-svelte transform returns compiled js for $DIR/js/vite-plugin-svelte-bug/node_modules/.pnpm/@inertiajs+inertia-svelte@0.8.0_fbnkmlyyx5hz7ybarl5bnfzfbq/node_modules/@inertiajs/inertia-svelte/src/InertiaLink.svelte
2022-06-04T19:58:00.683Z vite:vite-plugin-svelte transform returns compiled js for $DIR/vite-plugin-svelte-bug/node_modules/.pnpm/@inertiajs+inertia-svelte@0.8.0_fbnkmlyyx5hz7ybarl5bnfzfbq/node_modules/@inertiajs/inertia-svelte/src/Render.svelte
2022-06-04T19:58:00.894Z vite:vite-plugin-svelte error trying to resolve __vite-browser-external from �__vite-browser-external?commonjs-proxy via package.json svelte field  TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received '\x00__vite-browser-external?commonjs-proxy'
    at new NodeError (node:internal/errors:377:5)
    at createRequire (node:internal/modules/cjs/loader:1220:13)
    at resolveViaPackageJsonSvelte ($DIR/vite-plugin-svelte-bug/node_modules/.pnpm/@sveltejs+vite-plugin-svelte@1.0.0-next.47_svelte@3.48.0+vite@2.9.9/node_modules/@sveltejs/vite-plugin-svelte/dist/index.cjs:1476:59)
    at Object.resolveId ($DIR/vite-plugin-svelte-bug/node_modules/.pnpm/@sveltejs+vite-plugin-svelte@1.0.0-next.47_svelte@3.48.0+vite@2.9.9/node_modules/@sveltejs/vite-plugin-svelte/dist/index.cjs:1728:28)
    at $DIR/vite-plugin-svelte-bug/node_modules/.pnpm/rollup@2.75.5/node_modules/rollup/dist/shared/rollup.js:22974:37 {
  code: 'ERR_INVALID_ARG_VALUE'
}
‚úì 56 modules transformed.
rendering chunks...
dist/assets/main.02a1e324.js   69.45 KiB / gzip: 23.97 KiB

Validations

@sapphi-red
Copy link
Member

I got a different error for both dev and build.

X [ERROR] [plugin vite:dep-pre-bundle] Failed to resolve entry for package "object-inspect". The package may have incorrect main/module/exports specified in its package.json: Failed to resolve entry for package "object-inspect". The package may have incorrect main/module/exports specified in its package.json.
[commonjs] Failed to resolve entry for package "object-inspect". The package may have incorrect main/module/exports specified in its package.json: Failed to resolve entry for package "object-inspect". The package may have incorrect main/module/exports specified in its package.json.

And this error is true because util_inspect.js does not exist.
https://github.com/niczero/object-inspect/blob/e0bb215b068952a8276fc068f97fa435d1ba57ca/package.json#L75

@sapphi-red sapphi-red added the cannot reproduce The bug cannot be reproduced label Jun 8, 2022
@niczero
Copy link
Author

niczero commented Jun 8, 2022

The branches had got mixed up -- I've fixed the main branch on the repro repo so it does not contain the experiment with object-inspect.
Please try again.

@sapphi-red sapphi-red removed the cannot reproduce The bug cannot be reproduced label Jun 8, 2022
@sapphi-red
Copy link
Member

It seems these issues are related.
inspect-js/object-inspect#38
inertiajs/inertia#447

@sapphi-red sapphi-red added cannot reproduce The bug cannot be reproduced needs reproduction and removed cannot reproduce The bug cannot be reproduced labels Jun 8, 2022
@github-actions
Copy link

github-actions bot commented Jun 8, 2022

Hello @niczero. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@sapphi-red
Copy link
Member

@niczero Would you provide a reproduction for the runtime error? I was not able to reproduce it.

@niczero
Copy link
Author

niczero commented Jun 8, 2022

@niczero Would you provide a reproduction for the runtime error? I was not able to reproduce it.

Not really practical -- an inertia app requires a backend as well as a frontend -- so best to ignore the runtime error and treat it as a side memo on the build error.

@sapphi-red
Copy link
Member

@dominikg @bluwy May I ask you some questions about this issue? (sveltejs/vite-plugin-svelte#362, sveltejs/vite-plugin-svelte#363)

  1. Speaking of the error during build

  2. Speaking of the runtime error, it is hard to find the reason from the build error.

Am I right about these?

@dominikg
Copy link
Contributor

dominikg commented Jun 9, 2022

No, vite-plugin-svelte logged an error, but didn't actually resolve __vite-browser-external. We have since released a new version that does not log this error anymore. The behavior described by this report has not been caused/altered by that log statement.

As mentioned in sveltejs/vite-plugin-svelte#362 (comment) i suspect a combination of commonjs and browser field as a cause for this, but am not sure.

A clean reproduction with vite's vanilla template would be great. npm init vite -- --template vanilla

@niczero
Copy link
Author

niczero commented Jun 9, 2022

Status update:

  • You're right, the runtime error appears to be independent from the build error. I have avoided the build error (detail below) but with no build error I still get the runtime error, so I need to find a reproduction of the runtime error so we can get to the bottom of that.

I made a local hacked version of @inertiajs/inertia to produce an ESM build of that, using the patch attached here:
inertia_package.json.txt
When I swap from the official Inertia to the ESM Inertia, my repo has no build error. I think that shows the build error is not caused by vite-plugin-svelte and not caused by Axios. I am happy to use a hacked Inertia until the team there are able to resolve inertiajs/inertia#447

So the runtime error remains and I will try to build a mini reproduction.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants