Skip to content

ensure we don't resolve modules in parent folders #158

Description

@rchl

I've stumbled upon a crash trying to start a Nuxt 3-based project in a subdirectory of a Nuxt 2 project.

So the main Nuxt 2 project at /project/ and a Nuxt 3-based docs subdirectory at /project/docs. This crashes due to nuxt dependency from the root project getting picked up.

It seems the issue is in this code:

mlly/src/resolve.ts

Lines 75 to 79 in 6327ad8

new URL("./", url),
// If url is directory
new URL(joinURL(url.pathname, "_index.js"), url),
// TODO: Remove in next major version?
new URL("node_modules", url)

This _resolve function receives an id parameter with a nuxt value.
It creates url with the value of the current working directory so /project/docs.
Then new URL("./", url) actually resolves to the /project/ directory instead of /project/docs which seems very much not expected to me.

Try this in a browser:

new URL('./', 'file:///project/docs').href
"file:///project/"

(Same for the new URL("node_modules", url) line above which seems to be scheduled for removal at some point)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions