Giter Club home page Giter Club logo

valid-filename's Issues

Error [ERR_REQUIRE_ESM]

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"
  ]
}

ES modules is not supported

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

`.` and `..`

Totally forgot about them. How should we handle them? I think they're only invalid on Unix.

Improvements for Windows

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.
  • The names CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.