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

When using cwd flag with an absolute file path it fails to build. #598

Closed
chopfitzroy opened this issue Apr 30, 2020 · 4 comments
Closed

Comments

@chopfitzroy
Copy link

chopfitzroy commented Apr 30, 2020

I am using the following command:

"build:module": "cross-env-shell CONFIG_PATH=$pwd microbundle build --raw --cwd ./module/sub --alias @=$CONFIG_PATH --jsx React.createElement",

And in module/sub/package.json I have:

  "source": "index.js",

Now this all works as expected, however because of this PR in parcel source gets read in and parcel tries to compile from the source code which of course does not work because I am using the @ alias in my code so I can reference all of my modules with absolute paths instead of relative (originally I was doing this in raw rollup, as you can see now it is a bit convoluted using environment variables, could be a good argument for #249).

So in an attempt to alleviate this I tried removing the source entry and doing:

"build:module": "cross-env-shell CONFIG_PATH=$pwd microbundle build ./module/sub/index.js --raw --cwd ./module/sub --alias @=$CONFIG_PATH --jsx React.createElement",

Which gave me:

Error: Could not resolve entry module (module\sub\module\sub\index.js).

Which of course makes sense given I am using --cwd so I updated it to be:

"build:module": "cross-env-shell CONFIG_PATH=$pwd microbundle build ./index.js --raw --cwd ./module/sub --alias @=$CONFIG_PATH --jsx React.createElement",

This looked like it worked but it actually didn't generate any files and gave the following output:

Build "module" to dist:

Ideally I would be able to circumvent source where applicable in favor of absolute paths, I am going to open an issue on Parcel as well as it doesn't make sense to use the component source if parcel doesn't understand alias which are quite heavily used in the Vue world and other projects (the project I am working on is React for reference).

@chopfitzroy
Copy link
Author

chopfitzroy commented Apr 30, 2020

Related: #176

@chopfitzroy
Copy link
Author

Related Parcel Issue: parcel-bundler/parcel#4549

@developit
Copy link
Owner

developit commented May 22, 2020

Your build command is using cross-env-shell incorrectly. The command passed to cross-env-shell [KEY=VAL] command needs to be escaped using quotes, otherwise it will be interpreted by the shell rather than by cross-env. This isn't specific to microbundle, it's just how cross-env gets around cmd.exe replacing your $CONFIG_PATH variable with an empty string.

Also, when passing --cwd, all file paths in microbundle are now relative to that directory - it's essentially the same as doing cd $foo && microbundle ... That means instead of microbundle ./module/sub/index.js, you need to pass microbundle index.js.

Here's a working version - note the escaped quotes:

"scripts": {
  "build": "cross-env-shell CONFIG_PATH=$PWD \"microbundle build index.js --raw --cwd ./module/sub --alias @=$CONFIG_PATH --jsx React.createElement\""
}

I'm going to close this issue out since I'm 99% sure the issue is just this escapement thing, but please re-open it if that doesn't end up working.

As a helpful debugging step, you can prefix the whole microbundle command with echo to see what you're actually passing after cross-env-shell runs:

  "build": "cross-env-shell CONFIG_PATH=$PWD \"echo microbundle build index.js --raw --cwd ./module/sub --alias @=$CONFIG_PATH --jsx React.createElement\""

@developit
Copy link
Owner

FWIW, I would advise against using convenience aliases like @. They make your application bundler-specific when it doesn't have to be.

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

No branches or pull requests

2 participants