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

Build trying to compile every file in node_modules #727

Closed
ghost opened this issue Jul 13, 2021 · 6 comments
Closed

Build trying to compile every file in node_modules #727

ghost opened this issue Jul 13, 2021 · 6 comments

Comments

@ghost
Copy link

ghost commented Jul 13, 2021

For some reason, whenever I run ncc build in my project, it seems to attempt to compile every file inside of node_modules, ie.

Michaels-MacBook-Pro:deploy-app michaelplazek$ yarn build
yarn run v1.16.0
$ ncc build
ncc: Version 0.28.6
ncc: Compiling file index.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/auth-token/dist-node/index.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/auth-token/dist-src/hook.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/auth-token/dist-src/auth.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/auth-token/dist-src/index.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/auth-token/dist-src/types.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/auth-token/dist-src/with-authorization-prefix.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/auth-token/dist-web/index.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/core/dist-node/index.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/core/dist-src/index.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/core/dist-src/version.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/core/dist-src/types.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/core/dist-web/index.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/endpoint/dist-node/index.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/endpoint/dist-src/util/add-query-parameters.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/endpoint/dist-src/util/lowercase-keys.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/endpoint/dist-src/util/extract-url-variable-names.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/endpoint/dist-src/util/omit.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/endpoint/dist-src/util/merge-deep.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/endpoint/dist-src/util/remove-undefined-properties.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/endpoint/dist-src/util/url-template.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/endpoint/dist-src/endpoint-with-defaults.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/endpoint/dist-src/index.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/endpoint/dist-src/merge.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/endpoint/dist-src/parse.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/endpoint/dist-src/defaults.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/endpoint/dist-src/version.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/endpoint/dist-src/with-defaults.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/endpoint/dist-web/index.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/graphql/dist-web/index.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/graphql/dist-node/index.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/graphql/dist-src/error.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/graphql/dist-src/graphql.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/graphql/dist-src/index.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/graphql/dist-src/types.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/graphql/dist-src/version.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/graphql/dist-src/with-defaults.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/plugin-paginate-rest/dist-src/generated/paginating-endpoints.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/plugin-paginate-rest/dist-src/compose-paginate.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/plugin-paginate-rest/dist-src/index.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/plugin-paginate-rest/dist-src/iterator.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/plugin-paginate-rest/dist-src/normalize-paginated-list-response.js
ncc: Version 0.28.6
ncc: Compiling file deploy-app/node_modules/@octokit/plugin-paginate-rest/dist-src/paginating-endpoints.js
.
.
.

This continues until I Control + C out of it.

This makes no sense to me, as the similar project with the exact same dependencies (I compared the yarn.lock files) compiles with no problem.

Michaels-MacBook-Pro:deploy-root michaelplazek$ yarn build
yarn run v1.16.0
$ ncc build -o build
ncc: Version 0.28.6
ncc: Compiling file index.js
4719kB  build/index.js
4719kB  [4789ms] - ncc 0.28.6
✨  Done in 5.00s.

The package.json of my project is as follows:

{
  "name": "@saturn/deploy-app",
  "version": "1.0.0",
  "main": "index.mjs",
  "license": "SEE LICENSE IN LICENSE.md",
  "scripts": {
    "build": "ncc build"
  },
  "devDependencies": {
    "@vercel/ncc": "^0.28.6"
  },
  "dependencies": {
    "@actions/core": "^1.2.6",
    "@aws-sdk/client-cloudfront": "^3.17.0",
    "@aws-sdk/client-s3": "^3.16.0",
    "@aws-sdk/client-sts": "^3.16.0",
    "@saturn/mfe-scripts": "1.1.6",
    "mime": "^2.5.2"
  }
}

The code itself is quite innocuous. The imports are as follows:

import fs from 'fs';
import path from 'path';
import { setFailed, getInput, info } from '@actions/core';
import mfeScripts from '@saturn/mfe-scripts';
import S3 from '@aws-sdk/client-s3';
import STS from '@aws-sdk/client-sts';
// import CF from '@aws-sdk/client-cloudfront';
import mime from 'mime';

Is there anyone who has any idea why this could be happening?

@ghost
Copy link
Author

ghost commented Jul 13, 2021

I just noticed its even trying to compile my tests too.

ncc: Version 0.28.6
ncc: Compiling file deploy-app/__tests__/deploy-root.spec.js
.
.
.

@ghost
Copy link
Author

ghost commented Jul 14, 2021

This seems to be an issue with the static asset resolution. When I run yarn build --debug, I see:

Emitting directory /Users/michaelplazek/Git/saturn-github-actions/actions/deploy-app/**/*/**/* for static use in module /Users/michaelplazek/Git/saturn-github-actions/actions/deploy-app/deploy-app.mjs

Essentially, it's trying to compile every single file in the directory.

@ghost
Copy link
Author

ghost commented Jul 14, 2021

OK, so the issue seems to be from the use of getInput from @actions/core for my GitHub actions in conjunction with fs

When I replace:

const directory = getInput('directory');

with (static strings):

const directory = 'someting';

to be used like so:

export const getFiles = () => {
  try {
    return fs.readdirSync(path.join(process.cwd(), directory));
  } catch (e) {
    setFailed(`Failed to read files: ${e}`);
  }
};

then it compiles normally. This is a common usage - GitHub even recommends using ncc as the build tool for Actions - so this really seems like a bug to me.

@styfle
Copy link
Member

styfle commented Jul 14, 2021

Thanks for reporting this issue!

Using getInput() doesn't fail in every case so it would be helpful if you could provide the minimum steps to reproduce.

https://github.com/styfle/cancel-workflow-action/blob/b54f1a5f83cea0b2be160c391b76400f88c60274/src/index.ts#L34

Also note that ESM is not supported yet (see PR #720)

@alaingiller
Copy link

alaingiller commented Jul 16, 2021

Same behavior but with path.resolve().

let given input is a var from user input (I use commander):

  • it do not works like this path.resolve(input, 'myfile')
  • it works with a static string: path.resolve('aStaticString', 'myfile')
  • it works when it is called twice (this is currently my workaround): path.resolve(input, ''); path.resolve(input, 'myfile');
  • it works with @zeit/ncc package

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "resolveJsonModule": true,
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2019",
    "sourceMap": true,
    "outDir": "dist/my-lib",
    "moduleResolution": "node",
    "baseUrl": "./",
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "esModuleInterop": true,
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true
  },
  "exclude": ["node_modules", "dist", "**/*.spec.ts", "**/jest.*"],
  "include": ["src"]
}

@guybedford
Copy link
Contributor

I tried to replicate the above scenarios with the following:

test.mjs

import fs from 'fs';
import path from 'path';
import { setFailed, getInput, info } from '@actions/core';
import mime from 'mime';

getInput('test');

var input = eval('user input');
path.resolve(input, 'myfile');

running ncc build test.mjs but could not replicate the issue.

If you can provide a simple replication I can look into it further here.

@styfle styfle closed this as completed Dec 14, 2021
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

3 participants