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

Warning 'The following packages did not export their package.json file...' in case of non-svelte packages #244

Closed
telkamp opened this issue Jan 2, 2022 · 13 comments · Fixed by #254 or #255
Labels
enhancement New feature or request triage Awaiting triage by a project member

Comments

@telkamp
Copy link

telkamp commented Jan 2, 2022

Describe the problem

I'm always getting a warning message from vite:resolve when tslib is resolved:
[vite-plugin-svelte] The following packages did not export their package.json file so we could not check the "svelte" field. If you had difficulties importing svelte components from a package, then please contact the author and ask them to export the package.json file.
- tslib
(see index.ts:205)
The message is caused when somewhere in src/utils/resolve.ts:resolveViaPackageJsonSvelte(..) the error ERR_PACKAGE_PATH_NOT_EXPORTED occurs.
Because tslib Is a third-party lib that does not use Svelte, it does not make sense to check the "svelte" field.

Describe the proposed solution

It would be nice to have an option to exclude some libs from being checked for the "svelte" field.

Alternatives considered

None

Importance

nice to have

@telkamp telkamp added enhancement New feature or request triage Awaiting triage by a project member labels Jan 2, 2022
@bluwy
Copy link
Member

bluwy commented Jan 2, 2022

This sounds similar to sveltejs/kit#3053. This should be fixed in Vite 2.7.10. Can you confirm this is still happening in the latest version of Kit, Vite and vite-plugin-svelte? If so, it would be great if you can provide a repro

@telkamp
Copy link
Author

telkamp commented Jan 2, 2022

I'm not using SvelteKit, because my app will be hosted on an embedded server (not nodejs).
But I'm using the newest packages: vite 2.7.10 and @sveltejs/vite-plugin-svelte 1.0.0-next.33.

I have uploaded a small example causing the warning The following packages did not export their package.json file... here: https://github.com/telkamp/smui-example-vite
It seems that the warnings thrown by vite-plugin-svelte are not handeld by the "onwarn" handler, right? See vite.config.ts in my example.

@bluwy
Copy link
Member

bluwy commented Jan 8, 2022

I'm not seeing the warning in the repro. When I run npm run dev, the logs are:

Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/ripple/index.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/dom/index.js" points to missing source files
(node:1778) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /Users/bjorn/Work/repros/smui-example-vite/node_modules/tslib/package.json.
Update this package.json to use a subpath pattern like "./*".
(Use `node --trace-deprecation ...` to show where the warning was created)
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/ripple/util.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/ripple/component.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/ripple/adapter.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/ripple/constants.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/ripple/types.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/ripple/foundation.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/dom/focus-trap.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/dom/events.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/dom/ponyfill.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/dom/keyboard.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/base/component.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/base/foundation.js" points to missing source files

And for npm run build:

vite v2.7.10 building for production...
transforming (66) ../node_modules/@smui/common/dist/elements/Nav.svelte(node:1783) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /Users/bjorn/Work/repros/smui-example-vite/node_modules/tslib/package.json.
Update this package.json to use a subpath pattern like "./*".
(Use `node --trace-deprecation ...` to show where the warning was created)
✓ 103 modules transformed.
../dist/index.html                  0.49 KiB
../dist/assets/index.8c4bed50.js    3.64 KiB / gzip: 1.42 KiB
../dist/assets/vendor.25b7050f.js   38.35 KiB / gzip: 11.54 KiB
../dist/assets/index.5e69d31e.css   455.51 KiB / gzip: 43.85 KiB

(macos m1, node 16.13.0)


It seems that the warnings thrown by vite-plugin-svelte are not handeld by the "onwarn" handler, right?

Yes. onwarn is for Svelte compiler warnings only. The warning here is from vite-plugin-svelte

@telkamp
Copy link
Author

telkamp commented Jan 8, 2022

Thank you for the feedback!
The problem seems to depend on the current Node version: I used 17.3.0 before, and when I switch to 16.13.0 I get the same deprecation warning than you (and my former export warning disappears).
I can currently not rate if this might be a problem of the newest Node js or of vite-plugin-svelte. Could you please cross-check it with Node js 17.3.0?

@bluwy
Copy link
Member

bluwy commented Jan 8, 2022

Interesting. I checked node 17.3.0, but I had the same warnings. Dev is still running fine though:

Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/ripple/index.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/dom/index.js" points to missing source files
(node:10688) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /Users/bjorn/Work/repros/smui-example-vite/node_modules/tslib/package.json.
Update this package.json to use a subpath pattern like "./*".
(Use `node --trace-deprecation ...` to show where the warning was created)
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/ripple/util.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/ripple/component.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/ripple/adapter.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/ripple/constants.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/ripple/types.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/ripple/foundation.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/dom/ponyfill.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/dom/events.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/dom/keyboard.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/dom/focus-trap.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/base/component.js" points to missing source files
Sourcemap for "/Users/bjorn/Work/repros/smui-example-vite/node_modules/@material/base/foundation.js" points to missing source files

So maybe the node version isn't the issue here 🤔

@telkamp
Copy link
Author

telkamp commented Jan 8, 2022

I have no clue why you don't see this warning in your set up, maybe its because you are using a Mac while I'm using Windows. But I found something about this issue in rollup-plugin-svelte, discussed in May 2020.

The problem has somethng to do with the (external) module require-relative, used by src/utils/resolve.ts. require-relative will return ERR_PACKAGE_PATH_NOT_EXPORTED, because it uses the NodeJS require(). require() checks the exports field in package.json (see entry-point-export ) and generates that error (at least in newer NodeJS environments).

In my opinion this warning does not make sense in case of external modules not using Svelte, because the idea was to inform the user on potential problems with Svelte. Would there be a simple way to check if a module should use Svelte? Then the check in src/utils/resolve.ts could be skipped.

@bluwy
Copy link
Member

bluwy commented Jan 9, 2022

The problem has somethng to do with the (external) module require-relative, used by src/utils/resolve.ts. require-relative will return ERR_PACKAGE_PATH_NOT_EXPORTED, because it uses the NodeJS require(). require() checks the exports field in package.json (see entry-point-export ) and generates that error (at least in newer NodeJS environments).

Yes you're correct. This only happens for dependencies that you directly import though, so I was confused why the error reported for a transitive library (tslib). Perhaps our custom prebundling handling surface it.

In my opinion this warning does not make sense in case of external modules not using Svelte, because the idea was to inform the user on potential problems with Svelte. Would there be a simple way to check if a module should use Svelte? Then the check in src/utils/resolve.ts could be skipped.

The only best way to check if a module uses Svelte is (ironically) to check the package.json, which in this case was reporting the error in the first place. However the idea of this warning is to bring up problems in the nodejs ecosystem in general though (see nodejs/modules#445)

I don't think we should hide this warning altogether, so I was wondering when/how to reproduce it as it's not expected behaviour per my first paragraph.


Another hunch I have is that this is caused by vitejs/vite#3951 released in Vite 2.7.0-beta.7 perhaps you can try a version before that and see if the warning still arises?

It would be tricky for me to fix this without able to reproduce locally though, so I'm trying to toss some ideas 😅

@dominikg
Copy link
Member

dominikg commented Jan 9, 2022

Really wonder whats going on here because tslib should not be checked at all

@telkamp
Copy link
Author

telkamp commented Jan 9, 2022

Another hunch I have is that this is caused by vitejs/vite#3951 released in Vite 2.7.0-beta.7 perhaps you can try a version before that and see if the warning still arises?

I'm getting the same warning with Vite v2.7.0-beta.6:

> vite build
vite v2.7.0-beta.6 building for production...
transforming (132) ..\node_modules\engine.io-parser\build\esm\commons.js11:19:14 [vite-plugin-svelte] The following packages did not export their `package.json` file so we could not check the "svelte" field. If you had difficulties importing svelte components from a package, then please contact the author and ask them to export the package.json file.
[...]

@telkamp
Copy link
Author

telkamp commented Jan 9, 2022

Really wonder whats going on here because tslib should not be checked at all

When I remove the use of @smui/button in my example project, the warning is gone. So it seems that it is caused by external modules, using tslib indirectly.
As far as I understand the code, the modules listed in COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD will not be excluded from checks by done indirectly by require().

@bluwy
Copy link
Member

bluwy commented Jan 12, 2022

I'm not really sure how we can resolve this issue. I can't repro it to fix it, so this might have to be stagnant at the meantime. When #222 is resolved, it would also indirectly fix this though

@vfilatov
Copy link

vfilatov commented Feb 2, 2022

Still receiving such warning when I import native nodejs packages in endpoints.

[...]
.svelte-kit/output/client/_app/assets/pages/__layout.svelte-f054a79d.css   161.49 KiB / gzip: 24.11 KiB
.svelte-kit/output/client/_app/chunks/vendor-da02a2b1.js                   195.28 KiB / gzip: 54.96 KiB
vite v2.7.13 building SSR bundle for production...
transforming (254) src/app.css2:22:34 PM [vite-plugin-svelte] vite-plugin-svelte was unable to find package.json of the following packages and wasn't able to resolve via their "svelte" field.
If you had difficulties importing svelte components from a package, then please contact the author and ask them to export the package.json file.
- fs
- child_process
- os
- net
- https
- crypto
✓ 264 modules transformed.
.svelte-kit/output/server/manifest.json                                                17.71 KiB
.svelte-kit/output/server/app.js                                                       57.60 KiB
[...]

"@sveltejs/kit": "^1.0.0-next.257"
"@sveltejs/adapter-node": "^1.0.0-next.67"
'@sveltejs/vite-plugin-svelte': [email protected][email protected]

@bluwy
Copy link
Member

bluwy commented Feb 7, 2022

@vfilatov That is now fixed in 1.0.0-next.37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage Awaiting triage by a project member
Projects
None yet
4 participants