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

Using --entryFile flag with webpack doesn't work #2039

Closed
2 of 4 tasks
mentos1386 opened this issue Apr 21, 2023 · 5 comments · Fixed by #2043
Closed
2 of 4 tasks

Using --entryFile flag with webpack doesn't work #2039

mentos1386 opened this issue Apr 21, 2023 · 5 comments · Fixed by #2043

Comments

@mentos1386
Copy link

mentos1386 commented Apr 21, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When using --entryFile with nest start command to specify different file to run (repl.ts for example) doesn't work as intended when using webpack instead of tsc.

When using custom webpack.config.js in following manner to diagnose the issue:

module.exports = options => {
  console.log(options.output.filename);
  console.log(options.entry);
  return options;
}

We get the following output:

> nest start graphql --entryFile generate

apps/graphql/main.js
/workspace/apps/graphql/src/main.ts

webpack 5.79.0 compiled successfully in 1323 ms
Error: Cannot find module '/workspace/dist/apps/graphql/generate'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1021:15)
    at Function.Module._load (node:internal/modules/cjs/loader:866:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47

Which indicates that --entryFile has no affect on webpack and it continues to compile the main.ts which is defined in nest-cli.json as entryFile.

Using nest start --tsc --entryFile repl works as intended.

Minimum reproduction code

https://github.com/mentos1386/nest-cli-entryfile-repro

Steps to reproduce

  1. npm i
  2. npx nest start --entryFile repl

Expected behavior

repl.ts should be compiled and started.

Package version

9.4.0

NestJS version

9.4.0

Node.js version

16

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

Relates to #1691

@mentos1386
Copy link
Author

Workarround that we are using is:

In package.json

    "repl": "ENTRY_FILE=repl nest start graphql --watch --entryFile repl"

In webpack.config.js

const path = require('node:path');

module.exports = options => {
  const entryFile = process.env.ENTRY_FILE;
  const outputDir = path.dirname(options.output.filename);
  const sourceDir = path.dirname(options.entry);

  const getSourceFile = () => {
    if (entryFile) return `${sourceDir}/${entryFile}.ts`;
    return options.entry;
  };

  const getOutputFile = () => {
    if (entryFile) return `${outputDir}/${entryFile}.js`;
    return options.output.filename;
  };

  return {
    ...options,
    entry: getSourceFile(),
    output: {
      ...options.output,
      filename: getOutputFile(),
    },
  };
};

@micalevisk
Copy link
Member

Hi! Would you like to create a Pull Request to fix that?

@mentos1386
Copy link
Author

I was looking at the code and i couldn't easily figure out what's going on :(

@micalevisk
Copy link
Member

micalevisk commented Apr 21, 2023

@mentos1386 I guess that is due to this:

const entryFile = getValueOrDefault<string>(
configuration,
'entryFile',
appName,
);

export function getValueOrDefault<T = any>(

looks like that the configuration doesn't have the right entry file name?

@kamilmysliwiec
Copy link
Member

Let's track this here #2043

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants