sindresorhus / valid-filename Goto Github PK
View Code? Open in Web Editor NEWCheck if a string is a valid filename
License: MIT License
Check if a string is a valid filename
License: MIT License
This error appears when importing a function:
const valid_filename_1 = require("valid-filename");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module ***\node_modules\valid-filename\index.js from ***\dist\accounts.js not supported.
Instead change the require of index.js in ***\dist\accounts.js to a dynamic import() which is available in all CommonJS modules.
$ node -v
v17.1.0
OS: Windows 10
tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"target": "ESNEXT",
"sourceMap": true,
"outDir": "./dist",
"moduleResolution": "node",
"removeComments": true,
"strict": true,
"strictPropertyInitialization": true,
"alwaysStrict": true,
"noUnusedLocals": false, /* Report errors on unused locals. */
"noUnusedParameters": false, /* Report errors on unused parameters. */
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
"skipLibCheck": true
},
"exclude": [
"**/*.d.ts", // prevent d.ts overwrite error
"**/repository", // prevent d.ts overwrite error
"dist",
"node_modules"
]
}
I just wanted to quickly check the file name :(
Waiting for the debugger to disconnect...
internal/modules/cjs/loader.js:1102
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: node_modules/valid-filename/index.js
require() of ES modules is not supported.
require() of node_modules/valid-filename/index.js from dist/app/Mobile/Sightings.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /node_modules/valid-filename/package.json.
at new NodeError (internal/errors.js:322:7)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1102:13)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at Object.<anonymous> (dist/app/Mobile/Sightings.js:8:50)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32) {
code: 'ERR_REQUIRE_ESM'
}
Process finished with exit code 1
maybe even implement it :)
best regards
Stefan
Totally forgot about them. How should we handle them? I think they're only invalid on Unix.
Having type definitions would be nice; do you accept PRs? Thanks!
Hey, I'm looking for a module to be used in the browser which can validate filenames for multiple platforms and this seems to be the best fit but I noticed a few things missing for the Windows filename rules. The full story is available on MSDN. Particularly:
\u0000
to \u0031
are not allowed.I'd propose a optional platform
argument so one can target multiple platforms.
There's a few more subtle details like MAX_PATH
restrictions. I'd also suggest removing the current 256 char limit, as it is no longer valid for recent Windows 10 versions, and it's really just a wild guess imho as one cannot know the true limit without knowing the file's full (resolved) path.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.