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

Unexpected token 'export' #293

Closed
ksuewer opened this issue Apr 26, 2022 · 8 comments · Fixed by #303
Closed

Unexpected token 'export' #293

ksuewer opened this issue Apr 26, 2022 · 8 comments · Fixed by #303

Comments

@ksuewer
Copy link

ksuewer commented Apr 26, 2022

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,
  },
});
@jeffijoe
Copy link
Owner

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.

@ksuewer
Copy link
Author

ksuewer commented Apr 26, 2022

I'm compiling with tsc.
With awilix 6.0.0 everything is fine.

@ksuewer
Copy link
Author

ksuewer commented Apr 26, 2022

Seems like the *.d.ts files are not excluded any more. Maybe the syntax changed.

@jeffijoe
Copy link
Owner

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.

@ksuewer
Copy link
Author

ksuewer commented Apr 26, 2022

Yes, seems like there are several problems with fast-glob ignore patterns like this issue which is close to my issue: mrmlnc/fast-glob#357
I fixed it meanwhile by limiting to js files only :)

@jeffijoe
Copy link
Owner

jeffijoe commented May 2, 2022

We will have to wait until the issue is fixed in fast-glob.

@davidzwa
Copy link

davidzwa commented Jul 2, 2022

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
mrmlnc/fast-glob#357 (comment)

@jeffijoe
Copy link
Owner

jeffijoe commented Aug 1, 2022

I left a comment but no news yet.

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

Successfully merging a pull request may close this issue.

3 participants