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

Problems on build time #1

Closed
bolotin-taptima opened this issue Oct 2, 2020 · 8 comments
Closed

Problems on build time #1

bolotin-taptima opened this issue Oct 2, 2020 · 8 comments

Comments

@bolotin-taptima
Copy link

Trying to use this lib as described in readme, but got this error on build time:

> Build error occurred
/node_modules/first-di/dist/index.js:1
export * from "./classes/di";
^^^^^^

SyntaxError: Unexpected token 'export'
@LabEG
Copy link
Owner

LabEG commented Nov 28, 2020

Sory for long response. You need update version of nodejs for solve this problem.

@bolotin-taptima
Copy link
Author

I have Nodejs v14 installed, but still getting this error. Maybe the problem is that compiler does not process third-party files?

@LabEG
Copy link
Owner

LabEG commented Nov 28, 2020

Yep. Problem in build system. First DI drop support ES3 and compiled to ES2015. Because of this some old frameworks and build systems needs to be configured to support ES2015 in node_modules packages. As a rule, adding babel and configuring transpile in third-party packages solves this problem.

@bolotin-taptima
Copy link
Author

I've solved this error by replacing 'main' key in your package.json with 'module' key. See https://webpack.js.org/guides/author-libraries/#final-steps

@LabEG
Copy link
Owner

LabEG commented Nov 29, 2020

Thanks for help. I add module in package.json and published new version (first-di@0.1.29). Now you can upgrade and it will work out of the box.

But modules and ES2015 in main files it modern trend. And better way will fix bundle system to support this features in main files.

@bolotin-taptima
Copy link
Author

This error is still there (using Next.js@10 and its default build system). When I totally remove main key from package.json the error is gone.

@LabEG
Copy link
Owner

LabEG commented Dec 6, 2020

I found the problem. I made test project on next.js and just like you got an error with build. This problem is due to not-perfect build configuration in next.js.

To solve problem, I found this issues on oficial github of next.js:
vercel/next.js#706
react-syntax-highlighter/react-syntax-highlighter#230
and this package for solve same problems
https://www.npmjs.com/package/next-transpile-modules

Then I made next config:

// next.config.js
const withTM = require('next-transpile-modules')(['first-di']); // pass the modules you would like to see transpiled

module.exports = withTM();

After that, the problem was solved.

@LabEG
Copy link
Owner

LabEG commented Jul 8, 2021

Added to the build is a version of the build with commonjs modules.

Please try.

@LabEG LabEG closed this as completed Jul 8, 2021
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