Transitive dependency results in Vite build error while direct dependency does not
See original GitHub issueDescribe the bug
When adding a dependency @cognite/3d-web-parser in package.json
and importing something from it, everything runs fine.
However, when adding a dependency @cognite/3d-viewer which itself depends on @cognite/3d-web-parser
and including something from @cognite/3d-viewer
, Vite spits out a build error that it can not resolve the dependency @cognite/3d-web-parser
with the below error message:
[plugin vite:dep-scan] Failed to resolve entry for package "@cognite/3d-web-parser". The package may have incorrect main/module/exports specified in its package.json: Failed to resolve entry for package "@cognite/3d-web-parser". The package may have incorrect main/module/exports specified in its package.json.
When looking at the @cognite/3d-web-parser#package.json#module
entry, it does point to an existing index.es.js
file that does seem to be in ESM format.
It might have something to do w/ yarn
installing @cognite/3d-web-parser
under node_modules/@cognite/3d-viewer/node_modules/3d-web-parser
instead of installing it under @cognite/3d-web-parser
.
I’m not sure why Yarn doesn’t do that, though I’d also think that that shouldn’t pose a problem to Vite.
Reproduction
https://github.com/Robin-Hoodie/vite-resolve-failure-repro
System Info
System:
OS: macOS 12.3.1
CPU: (10) arm64 Apple M1 Pro
Memory: 4.00 GB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
Yarn: 1.22.18 - ~/.nvm/versions/node/v16.13.1/bin/yarn
npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm
Browsers:
Brave Browser: 101.1.38.115
Chrome: 101.0.4951.54
Safari: 15.4
npmPackages:
@vitejs/plugin-react: ^1.3.0 => 1.3.2
vite: ^2.9.9 => 2.9.9
Used Package Manager
yarn
Logs
vite:config bundled config file loaded in 47.63ms +0ms
vite:config using resolved config: {
vite:config plugins: [
vite:config 'vite:pre-alias',
vite:config 'alias',
vite:config 'vite:react-babel',
vite:config 'vite:react-refresh',
vite:config 'vite:react-jsx',
vite:config 'vite:modulepreload-polyfill',
vite:config 'vite:resolve',
vite:config 'vite:optimized-deps',
vite:config 'vite:html-inline-proxy',
vite:config 'vite:css',
vite:config 'vite:esbuild',
vite:config 'vite:json',
vite:config 'vite:wasm',
vite:config 'vite:worker',
vite:config 'vite:asset',
vite:config 'vite:define',
vite:config 'vite:css-post',
vite:config 'vite:worker-import-meta-url',
vite:config 'vite:client-inject',
vite:config 'vite:import-analysis'
vite:config ],
vite:config server: {
vite:config preTransformRequests: true,
vite:config https: true,
vite:config fs: { strict: true, allow: [Array], deny: [Array] }
vite:config },
vite:config resolve: { dedupe: [ 'react', 'react-dom' ], alias: [ [Object], [Object] ] },
vite:config optimizeDeps: {
vite:config include: [ 'react/jsx-dev-runtime' ],
vite:config esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
vite:config },
vite:config configFile: '/Users/robin/development/cognite/vite-resolve-failure-repro/vite.config.ts',
vite:config configFileDependencies: [
vite:config '/Users/robin/development/cognite/vite-resolve-failure-repro/vite.config.ts'
vite:config ],
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 server: {}
vite:config },
vite:config root: '/Users/robin/development/cognite/vite-resolve-failure-repro',
vite:config base: '/',
vite:config publicDir: '/Users/robin/development/cognite/vite-resolve-failure-repro/public',
vite:config cacheDir: '/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/.vite',
vite:config command: 'serve',
vite:config mode: 'development',
vite:config isWorker: false,
vite:config isProduction: false,
vite:config build: {
vite:config target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
vite:config polyfillModulePreload: true,
vite:config outDir: 'dist',
vite:config assetsDir: 'assets',
vite:config assetsInlineLimit: 4096,
vite:config cssCodeSplit: true,
vite:config cssTarget: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
vite:config sourcemap: false,
vite:config rollupOptions: {},
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 preview: {
vite:config port: undefined,
vite:config strictPort: undefined,
vite:config host: undefined,
vite:config https: true,
vite:config open: undefined,
vite:config proxy: undefined,
vite:config cors: undefined,
vite:config headers: undefined
vite:config },
vite:config env: { BASE_URL: '/', MODE: 'development', DEV: true, PROD: false },
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) {},
vite:config createResolver: [Function: createResolver],
vite:config worker: {
vite:config format: 'iife',
vite:config plugins: [
vite:config [Object], [Object],
vite:config [Object], [Object],
vite:config [Object], [Object],
vite:config [Object], [Object],
vite:config [Object], [Object],
vite:config [Object], [Object],
vite:config [Object], [Object],
vite:config [Object], [Object],
vite:config [Object]
vite:config ],
vite:config rollupOptions: {}
vite:config }
vite:config } +3ms
vite v2.9.9 dev server running at:
> Local: https://localhost:3000/
> Network: use `--host` to expose
ready in 115ms.
vite:deps scanning for dependencies... { timestamp: true } +0ms
vite:deps Crawling dependencies using entries:
vite:deps /Users/robin/development/cognite/vite-resolve-failure-repro/index.html +0ms
vite:resolve 0.26ms /src/main.tsx -> /Users/robin/development/cognite/vite-resolve-failure-repro/src/main.tsx +0ms
vite:resolve 1.15ms react -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/react/index.js +1ms
vite:resolve 0.50ms react-dom/client -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/react-dom/client.js +1ms
vite:resolve 0.30ms ./App -> /Users/robin/development/cognite/vite-resolve-failure-repro/src/App.tsx +1ms
vite:resolve 0.42ms @cognite/3d-viewer -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/@cognite/3d-viewer/dist/cognite.module.js +1ms
vite:deps Scan completed in 17.34ms: {
react: '/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/react/index.js',
'react-dom/client': '/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/react-dom/client.js',
'@cognite/3d-viewer': '/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/@cognite/3d-viewer/dist/cognite.module.js'
} +9ms
vite:resolve 0.31ms react/jsx-dev-runtime -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/react/jsx-dev-runtime.js +0ms
vite:deps dependencies found: @cognite/3d-viewer
vite:deps react
vite:deps react-dom/client
vite:deps react/jsx-dev-runtime { timestamp: true } +25ms
vite:resolve 0.30ms react-dom -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/react-dom/index.js +0ms
vite:resolve 0.29ms react -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/react/index.js +3ms
vite:resolve 1.44ms @babel/runtime/regenerator -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/@babel/runtime/regenerator/index.js +9ms
vite:resolve 1.58ms @babel/runtime/helpers/asyncToGenerator -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/@babel/runtime/helpers/asyncToGenerator.js +2ms
vite:resolve 1.20ms @babel/runtime/helpers/classCallCheck -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/@babel/runtime/helpers/classCallCheck.js +1ms
vite:resolve 1.41ms @babel/runtime/helpers/createClass -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/@babel/runtime/helpers/createClass.js +2ms
vite:resolve 0.57ms @tweenjs/tween.js -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/@tweenjs/tween.js/src/Tween.js +1ms
vite:resolve 0.37ms three -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/@cognite/3d-viewer/node_modules/three/build/three.module.js +0ms
vite:resolve 1.21ms @babel/runtime/helpers/toConsumableArray -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/@babel/runtime/helpers/toConsumableArray.js +2ms
vite:resolve 0.24ms right-now -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/right-now/browser.js +0ms
✘ [ERROR] [plugin vite:dep-pre-bundle] Failed to resolve entry for package "@cognite/3d-web-parser". The package may have incorrect main/module/exports specified in its package.json: Failed to resolve entry for package "@cognite/3d-web-parser". The package may have incorrect main/module/exports specified in its package.json.
node_modules/vite/dist/node/chunks/dep-59dc6e00.js:40662:10:
40662 │ throw new Error(`Failed to resolve entry for package "${id}". ` +
╵ ^
at packageEntryFailure (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/vite/dist/node/chunks/dep-59dc6e00.js:40662:11)
at resolvePackageEntry (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/vite/dist/node/chunks/dep-59dc6e00.js:40658:9)
at tryNodeResolve (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/vite/dist/node/chunks/dep-59dc6e00.js:40465:20)
at Context.resolveId (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/vite/dist/node/chunks/dep-59dc6e00.js:40273:28)
at Object.resolveId (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/vite/dist/node/chunks/dep-59dc6e00.js:38837:55)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/vite/dist/node/chunks/dep-59dc6e00.js:61503:27
at async /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/vite/dist/node/chunks/dep-59dc6e00.js:38354:34
at async callback (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/esbuild/lib/main.js:921:28)
at async handleRequest (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/esbuild/lib/main.js:701:30)
This error came from the "onResolve" callback registered here:
node_modules/vite/dist/node/chunks/dep-59dc6e00.js:38333:18:
38333 │ build.onResolve({ filter: /^[\w@][^:]/ }, async ({ path: id, importer, kind }) => {
╵ ~~~~~~~~~
at setup (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/vite/dist/node/chunks/dep-59dc6e00.js:38333:19)
at handlePlugins (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/esbuild/lib/main.js:843:23)
at Object.buildOrServe (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/esbuild/lib/main.js:1137:7)
at /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/esbuild/lib/main.js:2079:17
at new Promise (<anonymous>)
at Object.build (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/esbuild/lib/main.js:2078:14)
at Object.build (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/esbuild/lib/main.js:1927:51)
at runOptimizeDeps (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/vite/dist/node/chunks/dep-59dc6e00.js:39574:34)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
The plugin "vite:dep-pre-bundle" was triggered by this import
node_modules/@cognite/3d-viewer/dist/cognite.module.js:1:4088:
1 │ ...rray")},function(e,t){e.exports=require("right-now")},function(e,t){e.exports=require("@cognite/3d-web-parser")},function(e,t,n){"use strict";var r=this&&this.__assign||function(){return(r=Object....
╵ ~~~~~~~~~~~~~~~~~~~~~~~~
vite:resolve 0.69ms is-function -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/is-function/index.js +26ms
vite:resolve 0.40ms scheduler -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/scheduler/index.js +1ms
vite:resolve 0.40ms mouse-event-offset -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/mouse-event-offset/index.js +0ms
vite:resolve 1.17ms @babel/runtime/helpers/defineProperty -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/@babel/runtime/helpers/defineProperty.js +1ms
vite:resolve 0.25ms @cognite/three-combo-controls -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/@cognite/3d-viewer/node_modules/@cognite/three-combo-controls/dist/main.js +1ms
vite:resolve 0.95ms @babel/runtime/helpers/slicedToArray -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/@babel/runtime/helpers/slicedToArray.js +1ms
vite:resolve 0.88ms @babel/runtime/helpers/typeof -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/@babel/runtime/helpers/typeof.js +1ms
vite:resolve 0.22ms mixpanel-browser -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/mixpanel-browser/dist/mixpanel.cjs.js +0ms
vite:resolve 0.27ms simple-statistics -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/simple-statistics/dist/simple-statistics.js +0ms
vite:resolve 0.28ms regenerator-runtime -> /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/regenerator-runtime/runtime.js +1ms
12:24:42 PM [vite] error while updating dependencies:
Error: Build failed with 1 error:
node_modules/vite/dist/node/chunks/dep-59dc6e00.js:40662:10: ERROR: [plugin: vite:dep-pre-bundle] Failed to resolve entry for package "@cognite/3d-web-parser". The package may have incorrect main/module/exports specified in its package.json: Failed to resolve entry for package "@cognite/3d-web-parser". The package may have incorrect main/module/exports specified in its package.json.
at failureErrorWithLog (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/esbuild/lib/main.js:1603:15)
at /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/esbuild/lib/main.js:1249:28
at runOnEndCallbacks (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/esbuild/lib/main.js:1034:63)
at buildResponseToResult (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/esbuild/lib/main.js:1247:7)
at /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/esbuild/lib/main.js:1356:14
at /Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/esbuild/lib/main.js:666:9
at handleIncomingPacket (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/esbuild/lib/main.js:763:9)
at Socket.readFromStdout (/Users/robin/development/cognite/vite-resolve-failure-repro/node_modules/esbuild/lib/main.js:632:7)
at Socket.emit (node:events:390:28)
at addChunk (node:internal/streams/readable:315:12)
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
That makes sense. Thanks for all the help!
Closing this as the issue lies in
@cognite/3d-web-parser
and itspackage.json#browser
entryThe formats are same. browser ESM stands for ESM with browser specific code (like
window.alert
).