Module parse failed: /.../node_modules/any-promise/LICENSE Unexpected token
See original GitHub issueHi,
I am building an isomorphic project (code that can run in browser and in node) using webpack, and I am currently facing an weird issue and webpack does not give me enough data to understand what is going on (see stack trace below).
From what I know of webpack, it complains here that there is a dynamic require() (eg: require(var)
) so it try to resolve every possible path, and then it breaks on files like LICENSE, README etc…
Warning: %s Critical dependencies:
22:12-28 the request of a dependency is an expression
Warning: %s Module parse failed: /Users/moox/Sync/Development/putaindecode.io/node_modules/any-promise/LICENSE Unexpected token (1:14)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (1:14)
at Parser.pp$4.raise (/Users/moox/Sync/Development/putaindecode.io/node_modules/acorn/dist/acorn.js:2221:15)
at Parser.pp.unexpected (/Users/moox/Sync/Development/putaindecode.io/node_modules/acorn/dist/acorn.js:603:10)
at Parser.pp.semicolon (/Users/moox/Sync/Development/putaindecode.io/node_modules/acorn/dist/acorn.js:581:61)
at Parser.pp$1.parseExpressionStatement (/Users/moox/Sync/Development/putaindecode.io/node_modules/acorn/dist/acorn.js:966:10)
at Parser.pp$1.parseStatement (/Users/moox/Sync/Development/putaindecode.io/node_modules/acorn/dist/acorn.js:730:24)
at Parser.pp$1.parseTopLevel (/Users/moox/Sync/Development/putaindecode.io/node_modules/acorn/dist/acorn.js:638:25)
at Parser.parse (/Users/moox/Sync/Development/putaindecode.io/node_modules/acorn/dist/acorn.js:516:17)
at Object.parse (/Users/moox/Sync/Development/putaindecode.io/node_modules/acorn/dist/acorn.js:3098:39)
at Parser.parse (/Users/moox/Sync/Development/putaindecode.io/node_modules/webpack/lib/Parser.js:902:15)
at DependenciesBlock.<anonymous> (/Users/moox/Sync/Development/putaindecode.io/node_modules/webpack/lib/NormalModule.js:104:16) +1ms
Why are you using dynamic require? I have a workaround (to use webpack “externals” option) but this is causing me others issues as well, so I would like to know if we can do something over here to avoid this issue in the first place.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Module parse failed: Unexpected token. You may ... - GitHub
This is a library build issue. We moved to ts3.8 without thinking about optional chaining transpiling. Here seems like a correct way to...
Read more >Module parse failed: Unexpected token - Stack Overflow
Apparently it happened because you have two module properties in the webpack config object. Given JS objects can only hold one value per...
Read more >Odyssey Lift-off I: "Module parse failed: Unexpected token" Error
I am receiving this error message: Failed to compile. ./src/pages/tracks.js 43:10. Module parse failed: Unexpected token (43:10)
Read more >Module parse failed: Unexpected token - Expo SDK - Forums
Hello, I have been trying to make a PWA file from my currently working app, but I keep getting the same error in...
Read more >Module parse failed: Unexpected token (1:0) - Laracasts
Hello , After running npm run watch I see this error : ERROR in ./resources/js/components/irp/admin/EditGroup.vue 1:0 Module parse failed: Unexpected token ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here’s a quick workaround:
What this does is it simply replaces all requires/imports of
any-promise
with your choice of Promise implementation, e.g.bluebird
in my case. If you want to use the native Promise, try some simple polyfill, e.g.pinkie-promise
(itsindex.js
ismodule.exports = typeof Promise === 'function' ? Promise : require('pinkie')
), I think Webpack will eliminate the polyfill itself (don’t take my word on it though).@jeremejevs For the “simple polyfill” part you can try promise-monofill - a simple module that I wrote that always returns the native promise, with no polyfills. It should be even simpler than pinkie.