awilix
awilix copied to clipboard
Unexpected token 'export'
This error happens on startup since version 6.1.0
:
/project/dist/modules/foo/repository/FooBarRepository.d.ts:1
export default class FooBarRepository {
^^^^^^
SyntaxError: Unexpected token 'export'
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1032:15)
at Module._compile (node:internal/modules/cjs/loader:1067:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object._loadModulesDeps.require (/project/node_modules/awilix/lib/container.js:342:28)
at /project/node_modules/awilix/lib/load-modules.js:60:41
Might it have to do with replacing glob
by fast-glob
?
My project uses Typescript and I use loadModules
to load classes:
container.loadModules([
'modules/**/repository/!(*.spec|*.d|*.test).{js,ts}',
'modules/**/service/!(*.spec|*.d|*.test).{js,ts}',
], {
cwd: path.join(__dirname, '../'),
formatName: 'camelCase',
resolverOptions: {
lifetime: awilix.Lifetime.SINGLETON,
injectionMode: 'CLASSIC',
register: awilix.asClass,
},
});
Looks like you are trying to load es modules as if they are cjs?
What are you transpiling to? Are you using ts node? I don’t have much to go on.
I'm compiling with tsc
.
With awilix 6.0.0
everything is fine.
Seems like the *.d.ts files are not excluded any more. Maybe the syntax changed.
Its possible that fast-glob isn’t respecting that ignore pattern then. I haven’t had to add those myself though and I also use TypeScript.
Yes, seems like there are several problems with fast-glob ignore patterns like this issue which is close to my issue: https://github.com/mrmlnc/fast-glob/issues/357
I fixed it meanwhile by limiting to js files only :)
We will have to wait until the issue is fixed in fast-glob
.
FYI the issue of fast-glob has been closed, but the release has not happened (although it was mentioned). Maybe it is best to ping them https://github.com/mrmlnc/fast-glob/issues/357#issuecomment-1152909138
I left a comment but no news yet.