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

fix(next): Next project does not work out of the box #3442

Closed
mbasadi opened this issue Mar 11, 2024 · 1 comment · Fixed by #3620
Closed

fix(next): Next project does not work out of the box #3442

mbasadi opened this issue Mar 11, 2024 · 1 comment · Fixed by #3620
Labels
bug Something isn't working

Comments

@mbasadi
Copy link
Contributor

mbasadi commented Mar 11, 2024

Steps to reproduce the issue:

$ mkdir nextSample
$ cd nextSample
$ npx projen new nextjs-ts
$ npm run projen    

You will get an error like:

import { web } from "projen";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:77:18)

My temporary sloution was something like this:

import { TextFile, web } from "projen";
const project = new web.NextJsTypeScriptProject({
  defaultReleaseBranch: "main",
  name: "nextSample",
  projenrcTs: true,
});
// Update or create the 'default' task
const defaultTask = project.tasks.tryFind('default');
if (defaultTask) {
  defaultTask.reset();
  defaultTask.description = 'Synthesize project files';
  defaultTask.exec('ts-node --project tsconfig.projen.json .projenrc.ts');
} else {
  project.addTask('default', {
    description: 'Synthesize project files',
    steps: [{ exec: 'ts-node --project tsconfig.projen.json .projenrc.ts' }],
  });
}
new TextFile(project, 'tsconfig.projen.json', {
  lines: [
    '{',
    '  "extends": "./tsconfig.json",',
    '  "compilerOptions": {',
    '    "module": "commonjs"',
    '  },',
    '  "include": [',
    '    ".projenrc.ts"',
    '  ]',
    '}',
  ],
});
project.synth();

Note, to be able to tun npm run projen you have to overwrite tsconfig.dev.json and change module to commonjs

@mbasadi mbasadi changed the title Bug: Next project does not work out of the box fix(next): Next project does not work out of the box Mar 11, 2024
@mrgrain mrgrain added the bug Something isn't working label Mar 11, 2024
@raihan-ste
Copy link

fwiw I'm also running into this issue, tried with projen 0.81.0

@mergify mergify bot closed this as completed in #3620 Jun 2, 2024
mergify bot pushed a commit that referenced this issue Jun 2, 2024
Fixes #3442

As far as I understand tsconfig.dev.json will only used for projen synthing, so that the module could switch to commonjs without effecting the standard tsconfig for nextjs.
Another approach could be to switch to `npx tsx .projenrc.ts ` as default task for projen (https://www.typescriptlang.org/docs/handbook/modules/guides/choosing-compiler-options.html#im-using-tsx)


---
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants