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

[QUESTION] How do I compile code to run on the Web #836

Closed
yiescc opened this issue Dec 29, 2021 · 2 comments
Closed

[QUESTION] How do I compile code to run on the Web #836

yiescc opened this issue Dec 29, 2021 · 2 comments

Comments

@yiescc
Copy link

yiescc commented Dec 29, 2021

this is my code

//  index.ts
import EditorJS from '@editorjs/editorjs';
...

i run

ncc build index.ts -o ./ 

result:

/******/ (() => {
  // webpackBootstrap
  /******/ 'use strict';
  /******/ /* webpack/runtime/compat */
  /******/
  /******/ if (typeof __nccwpck_require__ !== 'undefined')
    __nccwpck_require__.ab = __dirname + '/';
  /******/
  /************************************************************************/
  var __webpack_exports__ = {};

  const div = document.createElement('div');
  div.id = 'editorjs';
  document.body.appendChild(div);

  module.exports = __webpack_exports__;
  /******/
})();


when i run in browser , i get

 Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'exports')

error form this code

module.exports = __webpack_exports__;

other error is

__dirname is undefined

error comes from this code

if (typeof __nccwpck_require__ !== 'undefined')
    __nccwpck_require__.ab = __dirname + '/';

so how can i compile code run in web ?

@huozhi
Copy link
Member

huozhi commented Dec 29, 2021

ncc is targeting nodejs runtime, if you want to bundle web related library maybe consider using webpack directly?

@yiescc
Copy link
Author

yiescc commented Dec 30, 2021

ok..

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