question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamic import and Vue cannot be used with webpack loader

See original GitHub issue

Code:


// index.js
async function main() {
  const mod = await import("./module");
  console.log(mod);
}
main();

// module.js
export const text = "Hello World";

Error:

ERROR in ./src/index.js
Module build failed (from (webpack)-obfuscator/dist/loader/index.js):
Error: SyntaxError: Unexpected token (2:20)
    at Function.parseCode (/Users/kevin/projects/webpack-obfuscator-demo/node_modules/webpack-obfuscator/dist/loader/index.js:63:23)
    at Function.getCommentedSource (/Users/kevin/projects/webpack-obfuscator-demo/node_modules/webpack-obfuscator/dist/loader/index.js:31:55)
    at Object.Loader (/Users/kevin/projects/webpack-obfuscator-demo/node_modules/webpack-obfuscator/dist/loader/index.js:84:63)

Webpack config:

// webpack.config.js
const path = require("path");
const WebpackObfuscator = require("webpack-obfuscator");

module.exports = {
  mode: "production",
  module: {
    rules: [
      {
        test: /\.js$/,
        include: [path.resolve(".", "src")],
        enforce: "post",
        use: {
          loader: WebpackObfuscator.loader,
          options: {
            rotateStringArray: true,
          },
        },
      },
    ],
  },
};

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
sanex3339commented, Aug 14, 2020
1reaction
sanex3339commented, Aug 14, 2020

So. I’ll fix that literal value moved to the string array. But i cannot fix that as foo part was removed from this export because this is escodegen problem. I’ll try to create the PR to that package, but it may be merged in few weeks or even months

Read more comments on GitHub >

github_iconTop Results From Across the Web

webpack - vue.js - dynamic imports results in error: Support for ...
I want to use lazy/dynamic imports because I am rebuilding my content management system which has many, many pages that may or may...
Read more >
Webpack and Dynamic Imports: Doing it Right - Medium
The problem is if you want to dynamically load a file, in this case, an image, Webpack by default generate a chunk for...
Read more >
Lazy Loading Routes | Vue Router
Vue Router supports dynamic imports out of the box, meaning you can ... In general, it's a good idea to always use dynamic...
Read more >
Features | Vite
You can NOT use variables or expressions in them. Dynamic Import #. Similar to glob import, Vite also supports dynamic import with variables....
Read more >
file-loader - webpack - JS.ORG
The file-loader resolves import / require() on a file into a url and emits ... This can be used to prepend or append...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found