deepkit-framework icon indicating copy to clipboard operation
deepkit-framework copied to clipboard

Errors when using dist/esm version of type-compiler

Open jelib3an opened this issue 2 years ago • 1 comments

I'm using the type compiler with Vite as described at #221. I'm getting various errors if I have type: module set in my package.json.

I've created a repo to reproduce the errors at https://github.com/jelib3an/vite-svelte-playground/tree/deepkit. In particular, you may want to look at the package.json and vite.config.ts files

git checkout deepkit
npm install
# to see the first error
npm run dev
# to see the second error
NODE_OPTIONS="--experimental-specifier-resolution=node" npm run dev

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'vite-svelte-playground/node_modules/@deepkit/type-compiler/dist/esm/src/compiler' imported from vite-svelte-playground/node_modules/@deepkit/type-compiler/dist/esm/index.js

Seems like compiler is missing a .js extension in the export statement. (Actually this happens with the cjs version as well) This is not a major problem because I can work around it by simply using NODE_OPTIONS="--experimental-specifier-resolution=node" npm run dev

SyntaxError: Named export 'NodeFlags' not found. The requested module 'typescript' is a CommonJS module, which may not support all module.exports as named exports.

Looking inside these files:

  • node_modules/@deepkit/type-compiler/dist/esm/src/compiler.js
  • node_modules/@deepkit/type-compiler/dist/esm/src/loader.js
  • node_modules/@deepkit/type-compiler/dist/esm/src/reflection-ast.js
  • node_modules/@deepkit/type-compiler/dist/esm/src/resolver.js

They should be importing typescript via the default export Instead of

import { NodeFlags } from 'typescript';

should be

import ts from 'typescript';
const { NodeFlags } = ts;

I managed to get something working by removing type: module from package.json and using the cjs version. However, this is no longer an option with the latest version of Vite.

jelib3an avatar Jul 18 '22 17:07 jelib3an

It would be great to see a fix for this at some point, I've wanted to get rid of my dependence on class-transformer for something a bit more performant for a while.

darkevilmac avatar Jul 30 '22 03:07 darkevilmac