Skip to content

Cannot import Dropzone.svelte from a local package with npm link Β #151

Closed
@EnigmaCurry

Description

@EnigmaCurry

I am getting setup to work on the Dropzone component on my local workstation, as a dependency in my app. So I think the right way to do that is to clone it locally and to use npm link, so that's what I'm doing:

  • clone svelte-file-dropzone locally.
    • npm install
    • npm run package
    • npm link
  • cd to my app project directory.
    • npm link svelte-file-dropzone
    • npm install
    • npm run build

In my own app I am importing it like this:

import Dropzone from "svelte-file-dropzone/Dropzone.svelte";

The build fails like this:

$ npm run build

> [email protected] build
> vite build

vite v5.0.11 building SSR bundle for production...
βœ“ 7 modules transformed.
[commonjs--resolver] Missing "./Dropzone.svelte" specifier in "svelte-file-dropzone" package
error during build:
Error: Missing "./Dropzone.svelte" specifier in "svelte-file-dropzone" package
    at e (file:///home/ryan/git/vendor/enigmacurry/easy-send-file/frontend/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:21914:25)
    at n (file:///home/ryan/git/vendor/enigmacurry/easy-send-file/frontend/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:21914:627)
    at o (file:///home/ryan/git/vendor/enigmacurry/easy-send-file/frontend/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:21914:1297)
    at resolveExportsOrImports (file:///home/ryan/git/vendor/enigmacurry/easy-send-file/frontend/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:29466:20)
    at resolveDeepImport (file:///home/ryan/git/vendor/enigmacurry/easy-send-file/frontend/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:29485:31)
    at tryNodeResolve (file:///home/ryan/git/vendor/enigmacurry/easy-send-file/frontend/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:29210:20)
    at Object.resolveId (file:///home/ryan/git/vendor/enigmacurry/easy-send-file/frontend/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:28978:28)
    at Object.handler (file:///home/ryan/git/vendor/enigmacurry/easy-send-file/frontend/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:67380:19)
    at file:///home/ryan/git/vendor/enigmacurry/easy-send-file/frontend/node_modules/rollup/dist/es/shared/node-entry.js:18670:40
    at async PluginDriver.hookFirstAndGetPlugin (file:///home/ryan/git/vendor/enigmacurry/easy-send-file/frontend/node_modules/rollup/dist/es/shared/node-entry.js:18570:28)

I tried changing the import to all of the following and none of them worked:

import Dropzone from "svelte-file-dropzone/Dropzone.svelte";
import Dropzone from "svelte-file-dropzone/components/Dropzone.svelte";
import Dropzone from "svelte-file-dropzone/lib/components/Dropzone.svelte";
import Dropzone from "svelte-file-dropzone/src/lib/components/Dropzone.svelte";

I think the fix is to include ./Dropzone.svelte in the package.json exports config, which I read about in the svelte packaging guide :

  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "svelte": "./dist/index.js"
    },
    "./Dropzone.svelte": {
      "types": "./dist/components/Dropzone.svelte.d.ts",
      "svelte": "./dist/components/Dropzone.svelte"
    }
  },

Although I have no idea why this fix is actually needed, I will open a PR in case you want to see the fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions