vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.43k stars 26.79k forks source link

isolatedModules Problems, being reset automatically #7959

Closed pkellner closed 5 years ago

pkellner commented 5 years ago

Bug report

When I upgrade my working in 8.1.0 project (I use typescript custom express server.ts), I get an error that says

[ error ] ERROR in C:/Users/pkellner/Documents/svcc-pwa2/svcc-server.ts
1:1 All files must be modules when the '--isolatedModules' flag is provided.
  > 1 | const jsonServer = require('json-server');
      | ^
    2 | const server = jsonServer.create();
    3 | const router = jsonServer.router('db.json');
    4 | const middlewares = jsonServer.defaults();
[DEBUG] pwa2: server.ts:asyncMiddleware called req.url:/presenter/2019/guinder-bhangoo-46187

It's odd because that file, svcc-server.ts has nothing to do with next but the problem happened when I upgraded my package.json to 9.0.1 and ran the package.

I followed the suggestion of setting --isolatedModules to false, that fixed my svcc-server.ts file to run but then next time I ran my next custom javascript server, it re-wrote my custom --isolatedModules flag (at least it told me, but seems pretty sneaky).

The following changes are being made to your tsconfig.json file:
  - compilerOptions.isolatedModules must be true (requirement for babel)
myylow commented 5 years ago

I also ran into trouble with this when upgrading, as we had Jest tests that weren't modules. The isolatedModules setting means every file must be a module (i.e. have at least one export statement in them). You should be able to fix it by adding a simple export default undefined to your svcc-server.ts file if it has no export currently.

Timer commented 5 years ago

Hey! We're really sorry about this -- however, this is a requirement because we use Babel.

If this option is not set, small bugs will appear in your application that would otherwise work in real TypeScript.

You can fix it by exporting something from your custom server, e.g. export default undefined. You could also exclude this file from type checking in your tsconfig.json, then create a tsconfig.server.json which includes only your server files and extends from tsconfig.json.

asherccohen commented 5 years ago

I must confirm that this is still an issue. Following @Timer suggestion of:

You could also exclude this file from type checking in your tsconfig.json, then create a tsconfig.server.json which includes only your server files and extends from tsconfig.json.

Does not fix the problem. Tslint ignores this setting and still shows the error: Parsing error: If "parserOptions.project" has been set for @typescript-eslint/parser, ...\next.config.js must be included in at least one of the projects provided. eslint

Including or excluding the file in tsconfig.json is completely ignored.

Victordmdb commented 5 years ago

By automatically setting isolatedModules we can't use composite which is required when use ts references, which are themselves useful for monorepo structure.

Any workaround for that?

asherccohen commented 4 years ago

Any progress on this?

cyrus-za commented 4 years ago

TS 3.8 might help with this isolatedModules issue. https://devblogs.microsoft.com/typescript/announcing-typescript-3-8/#type-only-imports-exports

gromov-io commented 3 years ago

image

fack...

mrbing47 commented 3 years ago

Hey! We're really sorry about this -- however, this is a requirement because we use Babel.

If this option is not set, small bugs will appear in your application that would otherwise work in real TypeScript.

You can fix it by exporting something from your custom server, e.g. export default undefined. You could also exclude this file from type checking in your tsconfig.json, then create a tsconfig.server.json which includes only your server files and extends from tsconfig.json.

I have read almost every StackOverFlow articles with the same solution, but every time I use this, I am getting error message

SyntaxError: Unexpected token 'export'
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:1056:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Object.require.extensions.<computed> [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:1059:12)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at main (/usr/local/lib/node_modules/ts-node/src/bin.ts:198:14)
    at Object.<anonymous> (/usr/local/lib/node_modules/ts-node/src/bin.ts:288:3)

Anyone here who has a valid ans?

softmarshmallow commented 3 years ago

This makes me totally unable to reuse all my ts packages....

langjy commented 3 years ago

Hey! We're really sorry about this -- however, this is a requirement because we use Babel.

If this option is not set, small bugs will appear in your application that would otherwise work in real TypeScript.

You can fix it by exporting something from your custom server, e.g. export default undefined. You could also exclude this file from type checking in your tsconfig.json, then create a tsconfig.server.json which includes only your server files and extends from tsconfig.json.

Another error appeared: SyntaxError: Unexpected token 'export' When I use 'export default undefined'

nvhai245 commented 2 years ago

Any update on this issue?

balazsorban44 commented 2 years ago

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.