1

I have a private npm package that I have published to AWS CodeArtifact so I can use it across a ReactJS App and NodeJS/Express API app.

Version 1.0.0 of this package is published to CodeArtifact.

In my ReactJS App, I have a dependency in package.json as "@name-space/name-of-package": "^1.0.0"

I’ve changed the registry for @name-space to point to the CodeArtifact URL. For all other packages I’m still using the default NPM registry (https://registry.npmjs.com). I have this configured via an .npmrc file in my ReactJs project.

When I try to deploy my ReactJS app via AWS Amplify I get an error in the build: ERR! Invalid Version: ^1.0.0

I’m new to virtually everything I’m working with here - creating private packages, CodeArtifact, and Amplify, so I’m not sure if I’m missing any steps.

I've tried removing the "^" from the version in the ReactJS package.json, but then I get ERR! Invalid Version: 1.0.0 when trying to build.

Any idea how I can get rid of this error and get a successful build of my ReactJS app deployed via Amplify?

1 Answer 1

2

You will also need to update your amplify.ymlto login to CodeArtifact. Here is an example...

frontend:
  phases:
    preBuild:
      commands:
        - pip3 install awscli --upgrade --user
        - aws codeartifact login --tool npm --repository repository_name --domain domain_name --domain-owner domain_owner_id
        - npm ci
Sign up to request clarification or add additional context in comments.

7 Comments

thanks @Alex. I get a warning about the pip3 command: "Running pip install with root privileges is generally not a good idea. Try pip3 install --user instead." I'm assuming I need to provide a username after --user...would that be an IAM user that has access to the package in CodeArtifact? I'm also getting an error, but I figured I'd get clarity on this question first. Thanks for the help!
I think it's ok to ignore this warning and drop the --user flag. This install is happening on an ephemerial build container. I've been running Amplify builds like this for over a year with success. Share your other error and I can help out there as well.
Ok great, thanks @Alex. Here is the error [INFO]: # Executing command: aws codeartifact login --tool npm --repository repo-name --domain domain-name --domain-owner 000 [WARNING]: An error occurred (AccessDeniedException) when calling the GetAuthorizationToken operation: User: arn:aws:sts::000:assumed-role/AemiliaControlPlaneLambda-CodeBuildRole-1PJH7JZRIQRPI/AWSCodeBuild-[GUID] is not authorized to perform: codeartifact:GetAuthorizationToken on resource: arn:aws:codeartifact:us-east-1:0123456789:domain/domain-name [ERROR]: !!! Build failed [ERROR]: !!! Non-Zero Exit Code detected
I had to remove some of the identifiers in my comment above to make the error fit
I notice that repo-name and domain-name are still filled in. You will need to drop in your CodeArtifact specific values there. You should be able to find them in the AWS Console.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.