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.

Can't resolve submodule import when module's "exports" field doesn't have * pattern

See original GitHub issue

Describe the bug

I use my company’s package Juno and import the file Button component with subpaths

import { RcButton } from "@ringcentral/juno/components/Buttons";

Vite complains these error image

When same code bundled with webpack, the path can be resolved correctly

workaround

option1: import the module, not the submodule

import { RcButton } from '@ringcentral/juno'

option2: add * pattern to @ringcentral/juno’s package.json

  "exports": {
    ".": {
      "node": {
        "module": "./es6/index.js",
        "require": "./index.js"
      },
      "default": "./es6/index.js"
    },
-    "./": {
-      "node": {
-        "module": "./es6/",
-        "require": "./"
-      },
-      "default": "./es6/"
-    }
- 
+    "./*": {
+    "node": {
+      "module": "./es6/*/index.js",
+       "require": "./*/index.js"
+     },
+     "default": "./es6/*/index.js"
+  }
}

Reproduction

https://github.com/IronLu233/report-vite-resolve-bug

System Info

System:
    OS: Linux 5.10 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
    Memory: 9.76 GB / 15.45 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.1/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm

Used Package Manager

pnpm

Logs

vite:config bundled config file loaded in 94.99ms +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:worker-import-meta-url',
  vite:config     'vite:asset',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:client-inject',
  vite:config     'vite:import-analysis'
  vite:config   ],
  vite:config   server: {
  vite:config     preTransformRequests: 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: '/home/iron/workspaces/demo/vite-pkg-export/vite.config.ts',
  vite:config   configFileDependencies: [ 'vite.config.ts' ],
  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: '/home/iron/workspaces/demo/vite-pkg-export',
  vite:config   base: '/',
  vite:config   publicDir: '/home/iron/workspaces/demo/vite-pkg-export/public',
  vite:config   cacheDir: '/home/iron/workspaces/demo/vite-pkg-export/node_modules/.vite',
  vite:config   command: 'serve',
  vite:config   mode: 'development',
  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: undefined,
  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 } +7ms
  vite:deps Crawling dependencies using entries:
  vite:deps   /home/iron/workspaces/demo/vite-pkg-export/index.html +0ms
  vite:resolve 0.53ms /src/main.tsx -> /home/iron/workspaces/demo/vite-pkg-export/src/main.tsx +0ms
  vite:resolve 3.06ms react -> /home/iron/workspaces/demo/vite-pkg-export/node_modules/.pnpm/react@17.0.2/node_modules/react/index.js +5ms
  vite:resolve 1.11ms react-dom -> /home/iron/workspaces/demo/vite-pkg-export/node_modules/.pnpm/react-dom@17.0.2_react@17.0.2/node_modules/react-dom/index.js +2ms
  vite:resolve 0.82ms ./App -> /home/iron/workspaces/demo/vite-pkg-export/src/App.tsx +2ms
  vite:resolve 4.31ms @ringcentral/juno/components/Buttons -> null +6ms
  vite:resolve 0.29ms @ringcentral/juno -> /home/iron/workspaces/demo/vite-pkg-export/node_modules/.pnpm/@ringcentral+juno@2.1.1_b2948bdf0e6e35d28745840a570fbdc9/node_modules/@ringcentral/juno/es6/index.js +1ms
  vite:deps Scan completed in 43.27ms: {
  react: '/home/iron/workspaces/demo/vite-pkg-export/node_modules/.pnpm/react@17.0.2/node_modules/react/index.js',
  'react-dom': '/home/iron/workspaces/demo/vite-pkg-export/node_modules/.pnpm/react-dom@17.0.2_react@17.0.2/node_modules/react-dom/index.js',
  '@ringcentral/juno': '/home/iron/workspaces/demo/vite-pkg-export/node_modules/.pnpm/@ringcentral+juno@2.1.1_b2948bdf0e6e35d28745840a570fbdc9/node_modules/@ringcentral/juno/es6/index.js'
} +29ms

Validations

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
IronLu233commented, Mar 11, 2022

😊. I will submit PR for it(This weekend)

0reactions
patak-devcommented, Mar 13, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to resolve modules specified in package.json's ...
I'm working on a JS web application and am trying to use the exports field in a package.json file to clean up the...
Read more >
Modules: Packages | Node.js v19.3.0 Documentation
Exports sugar; Subpath imports; Subpath patterns; Conditional exports ... Node.js has two systems for resolving a specifier and loading modules.
Read more >
Package exports - webpack
The exports field in the package.json of a package allows to declare which module should be used when using module requests like import...
Read more >
JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript ... Use of native JavaScript modules is dependent on the import...
Read more >
Support "exports" field of package.json : WEB-40509 - YouTrack
Actual: completes to import HelloDependency from "WEB-40509-dependency/lib/hello" . Run node index.js - it errors out, unable to find module under lib/lib .
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