How to browse when import, export, etc. are used in the js file of the node_module library.

Asked 2 years ago, Updated 2 years ago, 122 views

I use the browserify API to convert the code written in TypeScript into JavaScript and write the process of putting those codes together.
Below is the code that causes the problem.

(async()=>{

    let code = wait (() = > {
        const browserifyObject=browserify();
        browserifyObject.add(`${__dirname}/game.js`);
        return new Promise <string > ((resolve, reject) = > {
            browserifyObject.bundle(error,source)=>{
                if(error){
                    reject(error);
                    return;
                }
                const code = new TextDecoder().decode(source);
                resolve(code);
            });
        });
    })();

    // a variety of treatments

})();

Error Log

[SyntaxError: 'import' and 'export' may appear only with 'sourceType:module'] {
  line —1,
  column: 1,
  notated: '\n' +
    (Omitted) \\node_modules\\three\\examples\\jsm\\controls\\OrbitControls.js:1\n

I understand that the error occurred because import is used in JavaScript code in the file OrbitControls.js in the 3D library Three.js, but I cannot find a way to resolve it and cannot proceed at all.
I set the sourceType property to module according to the instructions in the error content, but the error content did not change.Professor, please.

typescript browserify

2022-09-30 17:06

1 Answers

The browserify project itself is not working very well, so we decided to adopt a webpack that we have used only a little once.[From comments]
Thank you.


2022-09-30 17:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.