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

blocker: nuxt-ts fails to start application when package installed globally with npm #175

Closed
georgyfarniev opened this issue Oct 30, 2019 · 4 comments

Comments

@georgyfarniev
Copy link

georgyfarniev commented Oct 30, 2019

Describe the bug

Hello. We experienced very strange issue. Unfortunately, this is very serious roadblock for us, since we cannot deploy our nuxt application in production environment, so I think it's correct to consider it as blocker. If this way to deploy package are not correct, please give us some advices how it should be deployed, since we followed docs of nuxt/typescript when it happened.

Also I think that other people should be notified about presence of this bug in docs main page and readme, so they will not start using it in production until this resolved, because it can be a critical issue for business.

The story:

On production, we install our packages from private npm registry, including our nuxt apps. When we tried to install nuxt app and run it, it fails with the following error message:


Username@machine MINGW64 ~/AppData/Roaming/npm/node_modules/nuxt_repro3
$ npm run start

> nuxt_repro3@1.0.0 start C:\Users\Username\AppData\Roaming\npm\node_modules\nuxt_repro3
> nuxt-ts start


 FATAL  Invalid or unexpected token

  const config: Configuration = {
  ^

  SyntaxError: Invalid or unexpected token
  at Module._extensions..js (internal/modules/cjs/loader.js:787:10)
  at Object.require.extensions.<computed> [as .ts] (node_modules\ts-node\src\index.ts:485:14)


   ╭──────────────────────────────────────────────╮
   │                                              │
   │   ✖ Nuxt Fatal Error                         │
   │                                              │
   │   SyntaxError: Invalid or unexpected token   │
   │                                              │
   ╰──────────────────────────────────────────────╯

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nuxt_repro3@1.0.0 start: `nuxt-ts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nuxt_repro3@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Username\AppData\Roaming\npm-cache\_logs\2019-10-30T11_50_17_825Z-debug.log


It looks like nuxt trying to load nuxt.config.ts as js file, but fails. Executing npm run start in sources dir works well, but not for global installation of the package. Doesn't matter if installed via private registry or tarball, failure are the same. It tried using following:

npm: 6.12.0
node: v12.6.0

Tested in both windows 10 and latest debian.

Reproduction link (with detailed description): https://github.com/georgyfarniev/nuxt_repro3

To Reproduce

  • npm install
  • npm run build
  • npm pack
  • npm install -g ./nuxt_repro3-1.0.0.tgz
  • cd `npm config get prefix`/node_modules/nuxt_repro3
  • npm run start

Expected behavior
Application starts correctly

Screenshots
N/A

Additional context
Might be probably related to #145, since it related to resolvers also.

UPD: Same issue happens when installed using yarn, and no matter if it installed globally or locally. So there is no way to run application after install via package :(

UPD2: It appears to be typescript-related issue, since just removing typescript keyword from nuxt.config.ts fixing this issue.

@kevinmarrec
Copy link
Contributor

kevinmarrec commented Oct 30, 2019

Is this bug reproducible when not using TypeScript and using ESM (export default and so on) inside nuxt.config.js.

I never seen yet poeple packaging a nuxt app to use it as a dependency so I'll need time to debug correctly

@georgyfarniev
Copy link
Author

georgyfarniev commented Oct 30, 2019

Is this bug reproducible when not using TypeScript and using ESM (export default and so on) inside nuxt.config.js.

No, it's only in case of typescript. If I remove typescript syntax from file, it works. Working example with ESM and no typescript:

const config = {
  mode: 'universal',
  buildModules: ['@nuxt/typescript-build']
}

export default config

I never seen yet poeple packaging a nuxt app to use it as a dependency

We are not using nuxt-based app as dependency, we are building package with application itself and deploying it to production as globally installed npm package. I don't know how other people deploy it, but I don't know other ways to do it properly. This is the way many packages use to distribute, such as verdaccio, anyproxy, redis commander just to name a few.

so I'll need time to debug correctly

Please let me know if I can do anything to help.

Thanks for quick reply.

@georgyfarniev
Copy link
Author

georgyfarniev commented Oct 31, 2019

@kevinmarrec important update: it breaks just if it lives inside directory named node_modules. Just create node_moduels anywhere, put nuxt_repro3 inside (with it's own deps ofc) and then try to start it, it will fail. Rename node_modules to mode_nodules and it will work. I suspect that this part are hardcoded somewhere.

UPD: found a reason: https://github.com/TypeStrong/ts-node/blob/master/src/index.ts#L206
This is why ts-node shouldn't be used it production.

UPD2: https://github.com/TypeStrong/ts-node#how-it-works

@kevinmarrec, should we add note to docs?

@kevinmarrec
Copy link
Contributor

ts-node shouldn't be indeed used in production.

As said earlier somewhere in another issue, we're working on making Nuxt production bundle TypeScript dependencies free, which will make what you want to achieve working without problems.

The issue here it's just cause typescript won't look after node_modules
No TypeScript code that would sit here should be handled by typescript, cause some of packages publish their TypeScript code source.

Pending work to track : #198

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

2 participants