sveltejs / svelte-loader

Webpack loader for svelte components.
MIT License
594 stars 73 forks source link

Option to disable resolve.conditionNames check #228

Open mon opened 1 year ago

mon commented 1 year ago

The documentation states:

If you're using Svelte components installed from npm, you should specify this option

I don't use any external Svelte components, and this explodes my webpack build output with errors from both Svelte and zip-js that look like:

Module not found: Error: Package path . is not exported from package C:\...\node_modules\svelte (see exports field in C:\...\node_modules\svelte\package.json)

Adding the fullySpecified: false check for svelte as mentioned in the README seems to solve the svelte errors, but I can't work out the right syntax to fix zip-js, so I'd just like to disable the warning entirely.

dehmer commented 1 year ago

Same problem here with OpenLayers. Build is OK without resolve.conditionNames: ['svelte'] and currently I also do not use external Svelte components. But what if we were to use external components?

I don't really understand how path aliases work and how this may interfere with OpenLayers (and other libraries), but for me this seems like a more involved problem to address.

If it helps, I can create a repo to reproduce this. Please let me know.

ERROR in ./node_modules/ol/layer/MapboxVector.js 9:0-60
Module not found: Error: Package path . is not exported from package /Users/dehmer/Development/bitbang.io/templates/9ec34c56/node_modules/ol-mapbox-style (see exports field in /Users/dehmer/Development/bitbang.io/templates/9ec34c56/node_modules/ol-mapbox-style/package.json)
 @ ./node_modules/ol/layer.js 10:0-64 10:0-64
 @ ./src/Map.svelte 15:0-45
 @ ./src/App.svelte 19:0-31 26:11-14
 @ ./src/main.js 3:0-31 5:16-19
ERROR in ./node_modules/ol/source/GeoTIFF.js 6:0-12:17
Module not found: Error: Package path . is not exported from package /Users/dehmer/Development/bitbang.io/templates/9ec34c56/node_modules/geotiff (see exports field in /Users/dehmer/Development/bitbang.io/templates/9ec34c56/node_modules/geotiff/package.json)
 @ ./node_modules/ol/source.js 12:0-55 12:0-55
 @ ./src/Map.svelte 14:0-32
 @ ./src/App.svelte 19:0-31 26:11-14
 @ ./src/main.js 3:0-31 5:16-19
giamir commented 1 year ago

@dummdidumm We do have a similar issues with this check in my project. I have noticed 2 problems:

I also notice that at least for configuration files written in TS this conditional return false even if the configuration is a function:

typeof config // { default: [Function (anonymous)] }

Thanks for your support.

morpheus7CS commented 1 year ago

Hey @dummdidumm,

I'm having a similar issue with our package that provides basic support for Svelte compilation in Laravel Mix.

Since many of our users have requested it, we have added support for svelte-loader, so that the end users can extend the configuration without us having to support a large API surface area.

This is the issue that got opened a few weeks back: https://github.com/wewowweb/laravel-mix-svelte/issues/31

The compilation itself doesn't fail, yet the warning is displayed, even though the configuration passed on by the user is correctly applied to the file. (thanks again @alesvaupotic for source-diving the configuration)

So far, the issue identified by @giamir seems to be the culprit for it, namely bullet point one:

Thanks, g

farfromrefug commented 8 months ago

Same issue here. I think the issue is that requiring our wepback.config.js wont work like that because we run it within a special environment (Nativescript). @dummdidumm :

codegain commented 6 months ago

I had the same error with these packages after adding svelte to conditionNames:

 error  in ./node_modules/sanitize-html/index.js                                                                                                1:38:35 PM

Module not found: Error: Package path . is not exported from package ./node_modules/htmlparser2 (see exports field in ./node_modules/htmlparser2/package.json)

 error  in ./node_modules/sanitize-html/index.js                                                                                                1:38:35 PM

Module not found: Error: Package path . is not exported from package ./node_modules/is-plain-object (see exports field in ./node_modules/is-plain-object/package.json)

 error  in ./node_modules/sanitize-html/index.js                                                                                                1:38:35 PM

Module not found: Error: Package path . is not exported from package ./node_modules/postcss (see exports field in ./node_modules/postcss/package.json)

and I'm using Symfony Encore to build my webpack.config.js file. Instead of adding only svelte to conditionNames, I also added browser and import which is only mentioned in the README under "Usage" in the full configuration (the array was not set before):

conditionNames: [ 'svelte', 'browser', 'import' ]

and now the warning + the 3 errors are gone. Maybe this helps someone.

EDIT: It seems like conditionNames: [ 'svelte', 'import' ] is enough in my case.

non25 commented 1 month ago

Hit this issue too. Here's the solution. :slightly_smiling_face:

morpheus7CS commented 1 month ago

@non25 thanks a lot!

@codegain does this solve it?

Kind regards, g