adobe / create-aio-lib

CLI tool to create Adobe I/O Libs (npm init @adobe/aio-lib)
Apache License 2.0
2 stars 5 forks source link

Project initialisation fails with error #38

Closed hannessolo closed 2 years ago

hannessolo commented 2 years ago

The example commands (both using npx and npm init) provided in the readme fail with an error.

Expected Behaviour

The repository is generated correctly running code npx @adobe/create-aio-lib AioLibHeadless AEMSnSDevX/aio-lib-headless

Actual Behaviour

The command errors:

➜  code npx @adobe/create-aio-lib AioLibHeadless AEMSnSDevX/aio-lib-headless
✖ ENOENT: no such file or directory, stat '/Users/hhertach/.npm/_npx/a3f913b00c8e91cb/node_modules/@adobe/create-aio-…
◼ Remove .git folder
◼ Read parameters file
◼ Update package.json
◼ Replace text
◼ Cleanup
◼ Lib Location
/Users/hhertach/.npm/_npx/a3f913b00c8e91cb/node_modules/@oclif/core/lib/errors/index.js:28
        err = new cli_2.CLIError(input, options);
              ^

CLIError: ENOENT: no such file or directory, stat '/Users/hhertach/.npm/_npx/a3f913b00c8e91cb/node_modules/@adobe/create-aio-lib/node_modules/@adobe/aio-lib-template'
    at Object.error (/Users/hhertach/.npm/_npx/a3f913b00c8e91cb/node_modules/@oclif/core/lib/errors/index.js:28:15)
    at CreateAioLibCommand.error (/Users/hhertach/.npm/_npx/a3f913b00c8e91cb/node_modules/@oclif/core/lib/command.js:103:23)
    at /Users/hhertach/.npm/_npx/a3f913b00c8e91cb/node_modules/@adobe/create-aio-lib/src/commands/create.js:99:14
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  oclif: { exit: 2 },
  code: undefined
}

Details

The issue is here: https://github.com/adobe/create-aio-lib/blob/3465de513ac28c653609d802bb2c46447e50ea5a/src/commands/create.js#L104

This works if create-aio-lib is cloned as a local repository, and therefore has its own node_modules directory containing the template. But it will not work if the template is installed as a peer of create-aio-lib, as it is in the context when running with npx.

Potential Fixes

The code at https://github.com/adobe/create-aio-lib/blob/3465de513ac28c653609d802bb2c46447e50ea5a/src/commands/create.js#L104 should be changed to use the normal node module resolution process, looking for the module first in the current directory, then the parent etc. I'm not sure if this can be achieved using a built-in, or needs to be implemented from scratch.

As a temporary workaround, I ran npm i @adobe/aio-lib-template in the directory where the CLI tool expected the template to be. Could be added as a workaround to the readme, but long-term, this is not a great solution.

Platform and Version

Mac 12.6, @adobe/create-aio-lib@2.0.0, node v16.14.2

shazron commented 2 years ago

Thanks @hannessolo. After investigation, the root cause is npm@7 and greater (the default with node-15 and greater), which uses npm exec for npx init now which appears to have different behaviour. With npm@6, it was working fine (default with node-14).

aiojbot commented 2 years ago

JIRA issue created: https://jira.corp.adobe.com/browse/ACNA-1861

shazron commented 2 years ago

To test you might have to add @latest so it picks up the latest version: npx @adobe/create-aio-lib@latest FooLib adobe/FooLib

hannessolo commented 2 years ago

Thanks for the quick fix!