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

Package subpath './package.json' is not defined by "exports" in /Users/xxx/my_repo/node_modules/cesium/package.json #8992

Closed
rapha-opensource opened this issue Jun 25, 2020 · 3 comments · Fixed by #9105

Comments

@rapha-opensource
Copy link

rapha-opensource commented Jun 25, 2020

This is Cesium installed via npm and integrated in a Svelte/Sapper route.

  1. npm install cesium
  2. Add a Svelte page to a Sapper basic demo app for the route /cesium which will load a basic Cesium Viewer.
  3. run npm run dev

The Svelte page

<script>
    import { onMount } from 'svelte'
    import "cesium/Build/Cesium/Widgets/widgets.css" // <= the first cesium import will cause the error !

    onMount(async () => {
        window.CESIUM_BASE_URL = 'http://localhost:3000/'
        const { Viewer } = await import('cesium')
        var viewer = new Viewer('cesiumContainer')
    })
</script>

<style>
    #cesiumContainer {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        overflow: hidden;
    }
</style>

<svelte:head>
    <title>Cesium Demo</title>
</svelte:head>
<div id="cesiumContainer"></div>

The error message

Package subpath './package.json' is not defined by "exports" in /Users/xxx/repos/my_repo/node_modules/cesium/package.json

Workaround

Delete the exports field in node_modules/cesium/package.json.
Re-launch npm run dev.

@mramato
Copy link
Contributor

mramato commented Jun 26, 2020

@rapha-opensource I would recommend you ask about this on https://community.cesium.com since no one on the Cesium team uses Svelte. Also, we use GitHub for confirmed bugs and feature tracking so it's always better to start there first anyway unless you are 100% sure of a bug.

exports is required for NodeJS compatibility, it was introduced in #8659. There's nothing non-standard about Cesium's behavior here so the problem is most likely on the svelte side (or whatever build tool you are using with it).

If you find out more information that points to something Cesium is doing wrong, please let us know and we can re-open the issue.

@mramato mramato closed this as completed Jun 26, 2020
@wallw-teal
Copy link
Contributor

This is an issue on more than just Svelte, as many bundler plugins check for config in package.json (react-native, etc.). The fix is not to remove the exports config, but to modify it to also contain ./package.json as was done in this commit.

I recommend re-opening and I'll be happy to add a PR.

@kring
Copy link
Member

kring commented Aug 18, 2020

Lots of tools need to require.resolve package.json, and in the latest versions of node.js it's impossible to do in a package with exports unless the package.json is explicitly exported. There's lots of discussion about this here:
nodejs/node#33460

But in the short term, I believe adding package.json to exports is a safe and effective solution. I'm going to re-open this, and I think we'd be happy to take a PR for it @wallw-bits.

@kring kring reopened this Aug 18, 2020
wallw-teal added a commit to wallw-teal/cesium that referenced this issue Aug 19, 2020
Many tools attempt to require.resolve package.json, and in the latest
versions of node that is not possible if the package specifies exports.
The solution is to simply add package.json to exports.

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

Successfully merging a pull request may close this issue.

4 participants