Home > database >  When trying to publish an npm package I get the following error: Did you mean to publish ./package/,
When trying to publish an npm package I get the following error: Did you mean to publish ./package/,

Time:01-04

I'm trying to publish my first npm package, but there seems to be something that I'm missing.

I have already tested the package with npm link and everything works as expected, however I am unable to publish it. I seem to be missing something, but can't find what it is.

Running npm publish or npm publish --dry-run give me the following error:

npm ERR! npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c echo 'Did you mean to publish ./package/, instead of ./?' && exit 1

My environment is:

  • Svelte Svelte kit
  • Vite
  • Typescript

My vite config is:

import { sveltekit } from '@sveltejs/kit/vite';

/** @type {import('vite').UserConfig} */
const config = {
   plugins: [sveltekit()]
};

export default config;

This is the complete log of the error:

0 verbose cli C:\Program Files\nodejs\node.exe C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js
1 info using [email protected]
2 info using [email protected]
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 2ms
5 timing config:load:file:C:\Users\user1\AppData\Roaming\nvm\v16.16.0\node_modules\npm\npmrc Completed in 2ms
6 timing config:load:builtin Completed in 2ms
7 timing config:load:cli Completed in 1ms
8 timing config:load:env Completed in 1ms
9 timing config:load:file:C:\Users\user1\Namu\sveltekit-auth0\.npmrc Completed in 1ms
10 timing config:load:project Completed in 4ms
11 timing config:load:file:C:\Users\user1\.npmrc Completed in 0ms
12 timing config:load:user Completed in 1ms
13 timing config:load:file:C:\Program Files\nodejs\etc\npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:credentials Completed in 1ms
17 timing config:load:setEnvs Completed in 0ms
18 timing config:load Completed in 12ms
19 timing npm:load:configload Completed in 12ms
20 timing npm:load:mkdirpcache Completed in 1ms
21 timing npm:load:mkdirplogs Completed in 1ms
22 verbose title npm publish
23 verbose argv "publish" "--dry-run"
24 timing npm:load:setTitle Completed in 1ms
25 timing config:load:flatten Completed in 2ms
26 timing npm:load:display Completed in 3ms
27 verbose logfile logs-max:10 dir:C:\Users\user1\AppData\Local\npm-cache\_logs
28 verbose logfile C:\Users\user1\AppData\Local\npm-cache\_logs\2023-01-02T20_06_32_635Z-debug-0.log
29 timing npm:load:logFile Completed in 4ms
30 timing npm:load:timers Completed in 0ms
31 timing npm:load:configScope Completed in 0ms
32 timing npm:load Completed in 22ms
33 verbose publish [ '.' ]
34 silly logfile start cleaning logs, removing 6 files
35 timing command:publish Completed in 63ms
36 verbose stack Error: command failed
36 verbose stack     at ChildProcess.<anonymous> (C:\Users\user1\AppData\Roaming\nvm\v16.16.0\node_modules\npm\node_modules\@npmcli\promise-spawn\lib\index.js:63:27)
36 verbose stack     at ChildProcess.emit (node:events:527:28)
36 verbose stack     at maybeClose (node:internal/child_process:1092:16)
36 verbose stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
37 verbose pkgid [email protected]
38 verbose cwd C:\Users\user1\Namu\sveltekit-auth0
39 verbose Windows_NT 10.0.22621
40 verbose node v16.16.0
41 verbose npm  v8.11.0
42 error code 1
43 error path C:\Users\user1\Namu\sveltekit-auth0
44 error command failed
45 error command C:\WINDOWS\system32\cmd.exe /d /s /c echo 'Did you mean to publish `./package/`, instead of `./`?' && exit 1
46 verbose exit 1
47 timing npm Completed in 111ms
48 verbose code 1
49 error A complete log of this run can be found in:
49 error     C:\Users\user1\AppData\Local\npm-cache\_logs\2023-01-02T20_06_32_635Z-debug-0.log

Any ideas?

I have tried modifying the vite.config.js file to something like:

import { sveltekit } from '@sveltejs/kit/vite';
import * as path from 'path';

/** @type {import('vite').UserConfig} */
const config = {
   plugins: [sveltekit()],
   resolve: {
      alias: [
         {
            find: '~',
            replacement: path.resolve(__dirname, './src')
         }
      ]
   },
   server: {
      port: 3000
   },
   build: {
      manifest: true,
      minify: true,
      reportCompressedSize: true,
      lib: {
         entry: path.resolve(__dirname, 'auth0/auth-service.ts'),
         fileName: 'auth-config',
         formats: ['es', 'cjs']
      },
      rollupOptions: {
         external: [],
         plugins: [sveltekit()]
      }
   }
};

export default config;

And similar configurations I found online, but it always produces the same error. I must be missing something.

CodePudding user response:

SvelteKit generates a package folder with a modified package.json that should be used for publishing. It lists all the exports contained in the library.

Hence you should cd into that directory and run npm publish there.

  • Related