Comments (7)
I think the issue is that hashbangs have to be at the start of the file (MDN):
A hashbang comment ... is only valid at the absolute start of a script or module. Note also that no whitespace of any kind is permitted before the
#!
. The comment consists of all the characters after#!
up to the end of the first line; only one such comment is permitted.
esmock
is inserting import
globals before the hashbang.
from esmock.
Very similar issue without hashbang.
foo.js
export default 1;
cli.js
import someConstant from "./foo.js";
console.log(someConstant);
1.js
import esmock from "esmock";
await esmock("./cli.js", {
"./foo.js": "bar",
});
file:///Users/xxxfoo.js?esmkTreeId=1&esmkModuleId=./foo.js&isfound=true&isesm=false&exportNames=0,1,2,default:1
export const 0 = global.esmockCacheGet("file:///Users/xxx/foo.js?esmkTreeId=1&esmkModuleId=./foo.js&isfound=true&isesm=false&exportNames=0,1,2,default").0
^
SyntaxError: Unexpected number
at CustomizedModuleLoader.moduleStrategy (node:internal/modules/esm/translators:116:18)
at CustomizedModuleLoader.moduleProvider (node:internal/modules/esm/loader:190:14)
from esmock.
esmock is inserting import globals before the hashbang.
I think you are correct :) thanks for finding this. I should have time this evening or tomorrow to look at PRs or try to resolve it myself
from esmock.
I don't know why the win32 error is occurring. The error indicates that paths like "node:fs" are only available in esm to packages using "type": "module", but the error originates inside an esm "load" hook and tests are started inside the tests-source-map folder which includes a package.json with "type": "module"
I don't know what causes the issue
from esmock.
related nodejs/node#35518
from esmock.
The ci error went away when node 18.16 was pinned. The error occurs on the latest 18.17
A new ticket is created at the node repo here let's see what they say nodejs/node#48948
from esmock.
closing with this #217
feel free to reopen for any reason
from esmock.
Related Issues (20)
- `invalid moduleId` in a TypeScript monorepo HOT 35
- yarn pnp issues HOT 14
- Is it possible to mock json imports with assert? HOT 6
- Support Yarn PnP resolver out of the box HOT 11
- Get rid of old Node versions support HOT 8
- resolve error introduced with 2.5.2 HOT 10
- Error when mocking a file that exports an array. HOT 1
- c8 incorrect branch coverage; modules and `import` globals HOT 11
- how to mock globalThis HOT 4
- import('node:fs/promises') called within a library does not seem to be replaced HOT 30
- Path alias support HOT 1
- Unexpected strict mode reserved word syntax error when mocking express HOT 2
- incompatible with eslint-plugin-import HOT 3
- No support for subpath patterns? HOT 14
- Version 2.6.3 changed the way to mock libraries HOT 7
- ESMock seems to wrongfully alter Sinon stubs. HOT 1
- Using `import:` to mock globals messes up coverage (with c8) HOT 7
- [Question] Is it possible to mock indirect imports? HOT 10
- Scoped mocks failing with pnpm but working with npm HOT 9
- esmock static import for classes not matching HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esmock.