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.

Missing "./package.json" export in "d3-scale" package (and others)

See original GitHub issue

Describe the bug

After upgrading my LayerChart visualization component library to SvelteKit 1.0.0-next.202 which includes Vite 2.7, I now receive a bunch of the following errors on startup for many d3 packages (d3-scale, d3-shape, d3-array, d3-time)…

12:29:01 PM [vite] Internal server error: Missing "./package.json" export in "d3-scale" package
  Plugin: vite:import-analysis
  File: /home/projects/sveltekit-gw2gco/node_modules/layercake/src/settings/defaultScales.js
      at bail (/home/projects/sveltekit-gw2gco/node_modules/vite/dist/node/chunks/dep-7817f5b4.js:29925:8)
      at resolve (/home/projects/sveltekit-gw2gco/node_modules/vite/dist/node/chunks/dep-7817f5b4.js:29978:7)
      at resolveExports (/home/projects/sveltekit-gw2gco/node_modules/vite/dist/node/chunks/dep-7817f5b4.js:30625:12)
      at resolveDeepImport (/home/projects/sveltekit-gw2gco/node_modules/vite/dist/node/chunks/dep-7817f5b4.js:30641:26)
      at tryNodeResolve (/home/projects/sveltekit-gw2gco/node_modules/vite/dist/node/chunks/dep-7817f5b4.js:30424:20)
      at viteResolve (/home/projects/sveltekit-gw2gco/node_modules/vite/dist/node/chunks/dep-7817f5b4.js:67443:26)
      at Function.eval [as _resolveFilename] (/home/projects/sveltekit-gw2gco/node_modules/vite/dist/node/chunks/dep-7817f5b4.js:67459:20)
      at Function.requireRelative.resolve (/home/projects/sveltekit-gw2gco/node_modules/require-relative/index.js:30:17)
      at resolveViaPackageJsonSvelte (file:///home/projects/sveltekit-gw2gco/node_modules/@sveltejs/vite-plugin-svelte/dist/index.js:1160:55)
      at Context.resolveId (file:///home/projects/sveltekit-gw2gco/node_modules/@sveltejs/vite-plugin-svelte/dist/index.js:1491:26)

What’s very perplexing is I didn’t have this issue last night and even deployed multiple times via Vercel without any issues.

Based on the error, it seems like the proper fix would be to update all d3 packages (ex. d3-scale) and add ./package.json to exports, although I’m not sure I’m up for PR’ing 50+ packages and how long it would take to get reviewed / merged / released. I also want to make sure its truly required as well 😃.

I’m also having trouble limiting the example below LayerChart (installing / importing either LayerCake (which LayerChart is built upon) or d3-scale does not throw the error. LayerChart also uses my svelte-ux component library which has some d3 references so I don’t know if it’s a transitive issue.


While writing this I just realized svelte-ux has the same issue, and is similar that it worked last night and deployed to Vercel multiple times.

Reproduction

Here are 2 StackBlitz reproductions for each project:

Logs

No response

System Info

System:
    OS: macOS 12.0.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 263.47 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.0 - /usr/local/bin/node
    npm: 8.1.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 96.0.4664.110
    Edge: 96.0.1054.57
    Firefox: 94.0.2
    Safari: 15.1
  npmPackages:
    @sveltejs/adapter-static: ^1.0.0-next.22 => 1.0.0-next.22 
    @sveltejs/kit: ^1.0.0-next.202 => 1.0.0-next.202 
    svelte: ^3.44.3 => 3.44.3

Severity

blocking an upgrade

Additional Information

Related?

Some related discussions with mhkeller in LayerCake (see referenced issues/PRs as well)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bluwycommented, Dec 19, 2021

Some initial investigation. I’m able to reproduce them in the stackblitz repros, but when I clone locally and run it, it worked without errors (macos m1). I can find the offending code through the stack trace, but it should technically still be fine. Gonna deep dive this tomorrow.

Otherwise, the workaround vite-plugin-svelte can do is to use createRequire instead of require-relative, but I’m trying to see if it’s a bug in Vite first.

0reactions
bluwycommented, Dec 31, 2021

Ah that’s really great news! This has been in my backlog for too long now. Closing this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node: Exports field in package.json is not working
I couldn't get exports to work. This is how I worked around it. I had to change the build + publish only the...
Read more >
The awkward valley to ESM: Node.js, Victory, and D3
This hits our package.json:exports field which translates victory-vendor/d3-scale to victory-vendor/es/d3-scale.js , which looks like:.
Read more >
D3js import typescript - Ionic Forum
For me the “rollup: Export 'select' is not defined by …” issue went away, by looking at the package.json file and upgrading the...
Read more >
package-lock.json - npm Docs
The difference is that package-lock.json cannot be published, and it will be ignored if found in any place other than the root project....
Read more >
What Is package.json? | heynode.com
It's the package.json file that enables npm to start your project, run scripts, install dependencies, publish to the NPM registry, and many other...
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