orlov-vo / parcel-transformer-svelte

Parcel 2 transformer for Svelte 3
https://www.npmjs.com/package/parcel-transformer-svelte
MIT License
40 stars 18 forks source link

Cannot read property 'raw' of null #15

Closed HarbingerNight closed 3 years ago

HarbingerNight commented 3 years ago

🚨 Build failed. parcel-transformer-svelte: Cannot read property 'raw' of null

Error on all parcel 2 svelte builds regardless of app. Have tested with multiple apps including Base Examples installed in clean directory. Same Error regardless.

Occurs w/ version 1.1.0 Works fine w/ version 1.0.8

orlov-vo commented 3 years ago

What version of Parcel you are using?

HarbingerNight commented 3 years ago

"parcel": "^2.0.0-beta.1", "parcel-transformer-svelte": "^1.1.0", "svelte": "^3.31.2"

fregante commented 3 years ago

Same for me, with a Parcel nightly. A non-minimal repro: https://github.com/npmhub/npmhub/blob/1c9ba30e4e5834175b03ef255d114eade49ed3ce/package.json

emirotin commented 3 years ago

config is literally null in transform

I've patched it locally (for now) to work like this:

diff --git a/node_modules/parcel-transformer-svelte/index.js b/node_modules/parcel-transformer-svelte/index.js
index 6a4fa00..6cdead3 100644
--- a/node_modules/parcel-transformer-svelte/index.js
+++ b/node_modules/parcel-transformer-svelte/index.js
@@ -55,12 +55,12 @@ exports.default = new Transformer({
     let code = await asset.getCode();
     const sourceFileName = relativeUrl(options.projectRoot, asset.filePath);
     const compilerOptions = {
-      ...config.raw.compilerOptions,
+      ...(config && config.raw && config.raw.compilerOptions || {}),
       filename: sourceFileName,
       name: generateName(sourceFileName),
     };

-    if (config.hydrated.preprocess) {
+    if (config && config.hydrated && config.hydrated.preprocess) {
       const preprocessed = await handleError(sourceFileName, () =>
         preprocess(code, config.hydrated.preprocess, compilerOptions),
       );

But I'm pretty much unsure if this is OK or just masking the real issue

UPD: so far it looks like the plugin doesn't expect people to be using the default Svelte config without any customizations.

orlov-vo commented 3 years ago

Thanks, you help me a lot because I hadn't time to check it on this week. I'll publish a new version soon.

emirotin commented 3 years ago

That was fast ;) Thanks