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

Allow passing in a custom project root — different from the config root. #7206

Open
pastelsky opened this issue Oct 27, 2021 · 7 comments
Open

Comments

@pastelsky
Copy link
Contributor

💬 RFC

Hi there, congratulations on the v2 release — the new site looks fantastic.
I'm currently evaluating switching Bundlephobia from Webpack to Parcel.

If I understand this correctly, one of the limitations of parcel 2 seems to be that the parcel configuration and plugins are resolved from the same directories (project root) as the source files being built.

It'd be great if it was possible to specify a project resolve root that was in a different directory tree than @parcel/core itself.

🔦 Context

How has this issue affected you? What are you trying to accomplish?
For bundlephobia's use case, the code to build packages lies in a different place than the code that gets built. This seems to be hard to do today with parcel without patching a bunch of packages.

@mischnic
Copy link
Member

You can use --config /path/to/parcelrc to use an arbitrary parcelrc file. Does that solve your problem?

@pastelsky
Copy link
Contributor Author

pastelsky commented Oct 28, 2021

@mischnic I'm using the programmatic API here. Also, curious, does the location of parcelrc actually set the project root?

This is my use case —

/build-runner
├── run-parcel.js
└── package.json (contains parcel core / plugins)

/project-to-build
├── entry-point.js
├── node_modules
└── package.json 

Here build-runner (where all of parcel's dependencies lie) is at a separate root than project-to-build, which contains runtime code to bundle.

when running parcel's programmatic API to build /project-to-build/entry-points.js from the /build-runner directory, it seems to treat build-runner as the project root, and imports inside entry-point.js seem to be resolved relative to build-runner instead of project-to-build.

@mischnic
Copy link
Member

This works correctly for me: https://github.com/mischnic/parcel-issue-7206

Does your "project" contain "yarn.lock", "package-lock.json", "pnpm-lock.yaml", ".git" or ".hg" file/folder?

Otherwise you might be running into this case here:

)) || path.join(inputCwd, 'index'); // ? Should this just be rootDir

So the cwd where the script is invoked from sets the root.

Also, curious, does the location of parcelrc actually set the project root?

No. It's based on the entry points (or in a special case, the project root, take a look at the full statement from the code snippet above).

@mlaigre
Copy link

mlaigre commented Dec 19, 2021

I also encountered it because my project folder does not contain any lock files as it is in a subfolder of a monorepo.

However, Parcel using monorepo root as the project root doesn't work for me so I had to create an empty .hg file.

echo "# to define Parcel root"> .hg

Allowing setting a custom project root seems to be a good way to resolve this issue.

@Duckers
Copy link

Duckers commented Jan 2, 2023

Bump - its very annoying that the location of the entry point file dictates what the root of the project is wrt HMR etc. Files outside the root are not watched

ire4ever1190 added a commit to automatarium/automatarium that referenced this issue Apr 4, 2023
ire4ever1190 added a commit to automatarium/automatarium that referenced this issue Apr 4, 2023
* Removed lockfiles in workspaces

Only the root workspace should have a lockfile

* Use a .hg file to specify root for parcel

Uses the solution here parcel-bundler/parcel#7206 (comment)
@macalinao
Copy link

super annoying but thanks for the .hg workaround!

@AnrDaemon
Copy link

AnrDaemon commented Mar 12, 2024

I've had to explicitly chdir to the root directory before starting build/serve command, else it was unable to find page requisites.

$ npx parcel serve --public-url=app/ app/index.html app/admin/index.html
Server running at http://localhost:1234
× Build failed.

@parcel/core: Failed to resolve '/jquery-ui.css' from './app/admin/index.html'
@parcel/resolver-default: Cannot load file './jquery-ui.css' in './'.

And it created a whole lot of trash in the webroot in that case. Not the result I expect. Even in development environment.

Another attempt

$ npx parcel serve --public-url=/ app/index.html app/admin/index.html
Server running at http://localhost:1234
× Build failed.

@parcel/core: Failed to resolve 'webmanifest:/site.webmanifest' from './app/admin/index.html'
@parcel/resolver-default: Cannot load file './site.webmanifest' in './'.
ℹ Did you mean './app/site.webmanifest'?
ℹ Did you mean './dist/site.webmanifest'?

Not a lot better…

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

No branches or pull requests

6 participants