svelte-preprocess icon indicating copy to clipboard operation
svelte-preprocess copied to clipboard

Named export 'sass' not found

Open basaran opened this issue 2 years ago • 7 comments

Describe the bug I'm trying to import and configure preprocessor manually.

To Reproduce

Repo: https://github.com/basaran/prep-issue

pnpm install -D svelte-preprocess;

then import in svelte.config.js

import { sass } from "svelte-preprocess";

Expected behavior I was able to import like this with a standard svelte project.

Stacktraces

If you have a stack trace to include, we recommend putting inside a <details> block for the sake of the thread's readability:

Stack trace

file:///home/michael/websites/prep/svelte.config.js:1 import { sass } from "svelte-preprocess"; ^^^^ SyntaxError: Named export 'sass' not found. The requested module 'svelte-preprocess' is a CommonJS module, which may not support all module.exports as named exports. CommonJS modules can always be imported via the default export, for example using:

import pkg from 'svelte-preprocess'; const { sass } = pkg;

at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:179:5)
at async Loader.import (node:internal/modules/esm/loader:178:24)
at async load_config (file:///home/michael/websites/prep/node_modules/.pnpm/@[email protected][email protected]/node_modules/@sveltejs/kit/dist/cli.js:697:17)
at async get_config (file:///home/michael/websites/prep/node_modules/.pnpm/@[email protected][email protected]/node_modules/@sveltejs/kit/dist/cli.js:769:10)
at async file:///home/michael/websites/prep/node_modules/.pnpm/@[email protected][email protected]/node_modules/@sveltejs/kit/dist/cli.js:831:18

Information about your project:

  • node v16.10.0
  • 4.9.8
  • Rollup

basaran avatar Nov 16 '21 08:11 basaran

I'm experiencing the same issue but with postcss

HeyITGuyFixIt avatar Nov 24 '21 17:11 HeyITGuyFixIt

I'm experiencing the same in a SvelteKit project. I've found that using the default import (e.g. import sveltePreprocess from 'svelte-preprocess';) and then calling the preprocessor method off of that (e.g. sveltePreprocess.sass()) works, but I don't like to have to do that since I should be able to use the ESM-style import (if I'm saying that correctly).

compeek avatar Jan 16 '22 06:01 compeek

bump! happened to me too

felixsanz avatar May 09 '22 13:05 felixsanz

I've run into this today and tracking back through the code it seems as though import { scss } from 'svelte-preprocess' should work.

SyntaxError: Named export 'scss' not found. The requested module 'svelte-preprocess' is a CommonJS module, which may not support all module.exports as named exports.

mattpilott avatar Jul 03 '22 14:07 mattpilott

hey, looks like this module only supports commonjs, remove "type": "module" from the package.json if you can.

muratgozel avatar Nov 16 '22 10:11 muratgozel

some issue happened to me

Aoshisen avatar Apr 12 '24 13:04 Aoshisen

some issue happened to me

image

Aoshisen avatar Apr 12 '24 13:04 Aoshisen

It seems vitePreprocess is becoming the norm these days. In the meantime, this is an option for destructuring assignment. Just not at the esm import.

import sveltePreprocess from 'svelte-preprocess';
const { sass } = sveltePreprocess;

basaran avatar Apr 13 '24 00:04 basaran