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

import.meta.dirname does not work in svelte.config.js #2290

Closed
hyunbinseo opened this issue Feb 13, 2024 · 1 comment
Closed

import.meta.dirname does not work in svelte.config.js #2290

hyunbinseo opened this issue Feb 13, 2024 · 1 comment
Labels

Comments

@hyunbinseo
Copy link

Describe the bug

In the svelte.config.js file, the newly added import.meta.dirname does not work.

// This works
join(dirname(fileURLToPath(import.meta.url)), 'postcss.config.js')

// This does not work
join(import.meta.dirname, 'postcss.config.js')

// These two values are identical
dirname(fileURLToPath(import.meta.url)) === import.meta.dirname;

The error is not shown in the svelte.config.js file.

It is only shown in Svelte files.

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined

Reproduction

// svelte.config.js

import adapter from '@sveltejs/adapter-node';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import { join } from 'node:path';

/** @type {import('@sveltejs/kit').Config} */
const config = {
  // Consult https://kit.svelte.dev/docs/integrations#preprocessors
  // for more information about preprocessors
  preprocess: vitePreprocess({
    style: {
      css: {
        postcss: join(import.meta.dirname, 'postcss.config.js'),
      },
    },
  }),
  kit: { adapter: adapter() },
};

export default config;

Expected behaviour

Following configuration should work in Node.js v20.11+

join(import.meta.dirname, 'postcss.config.js')

System Info

System:

  • OS: macOS 14.2.1
  • CPU: (10) arm64 Apple M1 Pro
  • Memory: 50.89 MB / 16.00 GB
  • Shell: 5.9 - /bin/zsh

Binaries:

  • Node: 20.11.0 - ~/.volta/tools/image/node/20.11.0/bin/node
  • npm: 10.2.4 - ~/.volta/tools/image/node/20.11.0/bin/npm
  • pnpm: 8.15.2 - ~/.volta/bin/pnpm

npmPackages:

  • @sveltejs/adapter-node: ^4.0.1 => 4.0.1
  • @sveltejs/kit: ^2.5.0 => 2.5.0
  • @sveltejs/vite-plugin-svelte: ^3.0.2 => 3.0.2
  • svelte: ^4.2.10 => 4.2.10
  • vite: ^5.1.1 => 5.1.1

Which package is the issue about?

No response

Additional Information, eg. Screenshots

Node v20.11.0 (LTS)

  • [c1a196c897] - (SEMVER-MINOR) esm: add import.meta.dirname and import.meta.filename (James Sumners) #48740
@hyunbinseo hyunbinseo added the bug Something isn't working label Feb 13, 2024
@jasonlyu123 jasonlyu123 added upstream and removed bug Something isn't working labels Feb 13, 2024
@jasonlyu123
Copy link
Member

By default, the language server is running on the version of node.js bundled with VSCode. It's 18.17.1 with VSCode 1.86.1. You can set the svelte.language-server.runtime to use another version for now but I don't think it's worth the effort since the workaround is simple enough.

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

No branches or pull requests

2 participants