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

"format*" script can't resolve to "bin-prettier.js" with a space in absolute path #321

Closed
MaGnaL opened this issue Mar 11, 2018 · 2 comments
Assignees

Comments

@MaGnaL
Copy link

MaGnaL commented Mar 11, 2018

Running one of the format* npm scripts fails, when there is a space in the absolute path to the workspace. Unfortunately format:write is called when a new app or Angular module lib is created.

In my case:

> my-workspace@0.0.0 format /Users/My Name/Documents/Development/my-workspace
> nx format write

module.js:549
    throw err;
    ^

Error: Cannot find module '/Users/My'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
child_process.js:644
    throw err;
    ^

Error: Command failed: node /Users/My Name/Documents/Development/my-workspace/node_modules/prettier/bin-prettier.js --single-quote --print-width 120 --write "{apps,libs}/**/*.ts"
    at checkExecSyncError (child_process.js:601:13)
    at Object.execSync (child_process.js:641:13)
    at write (/Users/My Name/Documents/Development/my-workspace/node_modules/@nrwl/schematics/src/command-line/format.js:58:25)
    at Object.format (/Users/My Name/Documents/Development/my-workspace/node_modules/@nrwl/schematics/src/command-line/format.js:19:13)
    at Object.<anonymous> (/Users/My Name/Documents/Development/my-workspace/node_modules/@nrwl/schematics/src/command-line/nx.js:15:18)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

I think the code which needs to be changed is this one:

function write(patterns: string[]) {
if (patterns.length > 0) {
execSync(`node ${prettierPath()} --single-quote --print-width 120 --write ${patterns.join(' ')}`, {
stdio: [0, 1, 2]
});
}
}
function check(patterns: string[]) {
if (patterns.length > 0) {
try {
execSync(`node ${prettierPath()} --single-quote --print-width 120 --list-different ${patterns.join(' ')}`, {
stdio: [0, 1, 2]
});
} catch (e) {
process.exit(1);
}
}
}
function prettierPath() {
const basePath = path.dirname(resolve.sync('prettier', { basedir: __dirname }));
return path.join(basePath, 'bin-prettier.js');
}

Since this kinda "blocks" the creation of apps and libs, the easiest workaround is to disable the format* scripts like described here: #306 (comment)

I'm using version 0.8.0.

Edit: And I'm on a Mac.

@MaGnaL MaGnaL changed the title format* can't resolve to "bin-prettier.js" with a space in absolute path "format*" script can't resolve to "bin-prettier.js" with a space in absolute path Mar 11, 2018
@FrozenPandaz FrozenPandaz self-assigned this Mar 22, 2018
@FrozenPandaz
Copy link
Collaborator

This should no longer be an issue as of 0.10.0

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants