Skip to content

Run time error from $app import inside node_modules component #4432

@janosh

Description

@janosh

Describe the bug

Is it possible to import $app from components inside node_modules?

Seems to work in most cases but just found an error trying to import

<script>
  import { afterNavigate } from '$app/navigation'
</script>

Not sure if this is really a bug or expected behavior?

Reproduction

npm init svelte@next test-after-nav-import # no to all questions
cd test-after-nav-import
npm i
mkdir node_modules/pkg
echo '{ "name": "pkg", "exports": { "./file.svelte": "./file.svelte" } }' >> node_modules/pkg/package.json
echo '<script> import { afterNavigate } from "$app/navigation"; </script>' >> node_modules/pkg/file.svelte
echo '<script> import File from "pkg/file.svelte"; </script> <File />' >> src/routes/index.svelte
npm run build
npm run preview

Open the site and I get

Uncaught TypeError: Cannot read properties of undefined (reading 'disable_scroll_handling') at vendor-15d5f540.js:1:7117

System Info

System:
    OS: macOS 12.2.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 340.23 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 17.6.0 - /opt/homebrew/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 8.5.1 - /opt/homebrew/bin/npm
  Browsers:
    Brave Browser: 99.1.36.117
    Safari: 15.3

Severity

serious, but I can work around it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions