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

Error upon importing barcode-detector/pure #117

Open
jp06 opened this issue Oct 9, 2024 · 4 comments
Open

Error upon importing barcode-detector/pure #117

jp06 opened this issue Oct 9, 2024 · 4 comments

Comments

@jp06
Copy link

jp06 commented Oct 9, 2024

Not really a big blocker but just want to let you know that when I was gonna write a custom polyfilling logic with the pure import but I got this error on build with Vite:

│ $ tsc && vite build
│ vite v5.2.11 building for production...
│ ✓ 12213 modules transformed.
│ x Build failed in 10.57s
│ error during build:
│ Error: [commonjs--resolver] Missing "./dist/es" specifier in "barcode-detector" package
│     at e (file:///Users/<redacted>/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:47597:25)
│     at n (file:///Users/<redacted>/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:47597:627)
│     at o (file:///Users/<redacted>/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:47597:1297)
│     at resolveExportsOrImports (file:///Users/<redacted>/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:48287:20)
│     at resolveDeepImport (file:///Users/<redacted>/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:48306:31)
│     at tryNodeResolve (file:///Users/<redacted>/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:48031:20)
│     at Object.resolveId (file:///Users/<redacted>/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:47781:28)
│     at file:///Users/<redacted>/node_modules/rollup/dist/es/shared/node-entry.js:19778:40
│     at async PluginDriver.hookFirstAndGetPlugin (file:///Users/<redacted>/node_modules/rollup/dist/es/shared/node-entry.js:19678:28)
│     at async resolveId (file:///Users/<redacted>/node_modules/rollup/dist/es/shared/node-entry.js:18359:26)

I am able to import barcode-detector just fine.

I have this vite.json extended by the tsconfig.json:

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "extends": "./react-library.json",
  "Display": "Vite",
  "moduleResolution": "node",
  "compilerOptions": {
    "target": "ESNext",
    "lib": ["DOM", "DOM.Iterable", "ES2020"],
    "types": ["vite/client"],
    "allowJs": false,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "module": "ESNext",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "forceConsistentCasingInFileNames": true
  }
}
@Sec-ant
Copy link
Owner

Sec-ant commented Oct 10, 2024

The commonjs resolver shouldn't be looking for "./dist/es". If you can provide a minimal repo to reproduce this error it would be of much help.

@jp06
Copy link
Author

jp06 commented Oct 10, 2024

I'll try later today, but a quick info is that my code is a private fork of this repo: https://github.com/bigcommerce/b2b-buyer-portal

@Sec-ant
Copy link
Owner

Sec-ant commented Oct 10, 2024

I think subpath exports are not supported by "moduleResolution": "node": https://stackoverflow.com/a/74538429 or it's very difficult to get it right. And the tsconfig document says You probably won’t need to use node10 in modern code.. Try changing it to bundler.

Additional links:

@jp06
Copy link
Author

jp06 commented Oct 10, 2024

Thanks, appreciate the help. I noticed that the moduleResolution is actually not even under the compilerOptions. Other import issues crop up though even if moduleResolution fixes thebarcode-detector/pure import , probably due to how it is set up, so I don't think I'll change it. In my case, the barcode-detector import already fine so I'll just use that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants